return simple String[] or List<String>

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

return simple String[] or List<String>

Tomáš Procházka-2

It's possible return simple String[] or List<String> with ibatis maping?

In documentation is only 'int' 'hashmap' and collection of own class.
Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work

--
Tomas Prochazka

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Maciej Radochonski
Hi Tomas,

You can use "queryForList". It will return a List<?> of objects specified in resultMap/resultClass.

-- 
Regards,
Maciej Radochonski
[hidden email]
----------------------------------------------------------------
http://www.mradochonski.com
http://www.linkedin.com/in/mradochonski
----------------------------------------------------------------
Any fool can write code that a computer can understand. Good programmers write code that humans can understand


2010/3/24 Tomáš Procházka <[hidden email]>

It's possible return simple String[] or List<String> with ibatis maping?

In documentation is only 'int' 'hashmap' and collection of own class.
Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work

--
Tomas Prochazka

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Larry Meadors
In reply to this post by Tomáš Procházka-2
You want result*Class*="java.util.String" - not result*Map*="java.util.String".

Larry

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Guy Rouillier-2
In reply to this post by Tomáš Procházka-2
On 3/24/2010 10:30 AM, Tomáš Procházka wrote:
>
> It's possible return simple String[] or List<String>  with ibatis maping?

You don't mention which version of iBATIS you are using, so I'm assuming
version 3.  This works:

        <select id="selectBundleId" resultType="string" parameterType="string" >


> In documentation is only 'int' 'hashmap' and collection of own class.
> Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work

The documentation says this: "Note that in the case of collections, this
should be the type that the collection contains, not the type of the
collection itself."  The type that the collection contains is string.

--
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Ingmar Lötzsch
Class String is in package java.lang.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Tomáš Procházka-2
In reply to this post by Guy Rouillier-2

I found solution i have this in xml mapping file

 <resultMap type="java.lang.String" id="domainsResult">
   <result property="" column="domain"/>
 </resultMap>

<select id="selectAvailableDomains" resultMap="domainsResult">
 SELECT domain FROM queue WHERE ended IS NULL GROUP BY domain
</select>

and this in Mapper class

List<String> selectAvailableDomains();

and it works


______________________________________________________________

> Od: "Guy Rouillier" <[hidden email]>
> Komu: [hidden email]
> Datum: 24.03.2010 18:10
> Předmět: Re: return simple String[] or List<String>
>
>On 3/24/2010 10:30 AM, Tomáš Procházka wrote:
>>
>> It's possible return simple String[] or List<String>  with ibatis maping?
>
>You don't mention which version of iBATIS you are using, so I'm assuming version 3.  This works:
>
> <select id="selectBundleId" resultType="string" parameterType="string" >
>
>
>> In documentation is only 'int' 'hashmap' and collection of own class.
>> Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work
>
>The documentation says this: "Note that in the case of collections, this should be the type that the collection contains, not the type of the collection itself."  The type that the collection contains is string.
>
>-- Guy Rouillier
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Guy Rouillier-2
Sure, that will work, but what is the point?  That result map doesn't
really buy you anything.  Why not just specify a resultType in your
select instead of a resultMap?

On 3/25/2010 7:43 AM, Tomáš Procházka wrote:

>
> I found solution i have this in xml mapping file
>
>   <resultMap type="java.lang.String" id="domainsResult">
>     <result property="" column="domain"/>
>   </resultMap>
>
> <select id="selectAvailableDomains" resultMap="domainsResult">
>   SELECT domain FROM queue WHERE ended IS NULL GROUP BY domain
> </select>
>
> and this in Mapper class
>
> List<String>  selectAvailableDomains();
>
> and it works
>
>
> ______________________________________________________________
>> Od: "Guy Rouillier"<[hidden email]>
>> Komu: [hidden email]
>> Datum: 24.03.2010 18:10
>> Předmět: Re: return simple String[] or List<String>
>>
>> On 3/24/2010 10:30 AM, Tomáš Procházka wrote:
>>>
>>> It's possible return simple String[] or List<String>   with ibatis maping?
>>
>> You don't mention which version of iBATIS you are using, so I'm assuming version 3.  This works:
>>
>> <select id="selectBundleId" resultType="string" parameterType="string">
>>
>>
>>> In documentation is only 'int' 'hashmap' and collection of own class.
>>> Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work
>>
>> The documentation says this: "Note that in the case of collections, this should be the type that the collection contains, not the type of the collection itself."  The type that the collection contains is string.
>>
>> -- Guy Rouillier
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

Tomáš Procházka-2
Hi.

But  what I must specify to resulType if I want return List<String> as
return value from query?


--------------------------- Původní zpráva ---------------------------
 Odesilatel: Guy Rouillier <[hidden email]>
    Předmět: return simple String[] or List<String>
      Datum: 25. března 2010, 15:27:31 (GMT -0400)
    Přílohy: <none>

G> Sure, that will work, but what is the point?  That result map doesn't
G> really buy you anything.  Why not just specify a resultType in your
G> select instead of a resultMap?

G> On 3/25/2010 7:43 AM, Tomáš Procházka wrote:

>> I found solution i have this in xml mapping file

>>   <resultMap type="java.lang.String" id="domainsResult">
>>     <result property="" column="domain"/>
>>   </resultMap>

>> <select id="selectAvailableDomains" resultMap="domainsResult">
>>   SELECT domain FROM queue WHERE ended IS NULL GROUP BY domain
>> </select>

>> and this in Mapper class

>> List<String>  selectAvailableDomains();

>> and it works


>> ______________________________________________________________
>>> Od: "Guy Rouillier"<[hidden email]>
>>> Komu: [hidden email]
>>> Datum: 24.03.2010 18:10
>>> Předmět: Re: return simple String[] or List<String>

>>> On 3/24/2010 10:30 AM, Tomáš Procházka wrote:

>>>> It's possible return simple String[] or List<String>   with ibatis maping?

>>> You don't mention which version of iBATIS you are using, so I'm assuming version 3.  This works:

>>>      <select id="selectBundleId" resultType="string" parameterType="string">


>>>> In documentation is only 'int' 'hashmap' and collection of own class.
>>>> Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work

>>> The documentation says this: "Note that in the case of collections, this should be the type that the collection contains, not the type of the collection itself."  The type that the collection contains is string.

>>> -- Guy Rouillier





------------------------ Konec původní zprávy ------------------------

--
---------------------------------------------------------------------
 Tomáš Procházka


 E-mail: [hidden email]
    WWW: http://www.atomsoft.cz
    ICQ: 87147320
---------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

nmaves
Tomas,

I am assuming that you have not read the developers guide and I just
giving things a go.  You need to read the guide completely.

In this case Guy was saying that if your query only returns a string
then set the resultType to String.  Then use the ibatis queryForList()
to compile your results into a List<String>.

Nathan

2010/4/11 Tomáš Procházka <[hidden email]>:

> Hi.
>
> But  what I must specify to resulType if I want return List<String> as
> return value from query?
>
>
> --------------------------- Původní zpráva ---------------------------
>  Odesilatel: Guy Rouillier <[hidden email]>
>    Předmět: return simple String[] or List<String>
>      Datum: 25. března 2010, 15:27:31 (GMT -0400)
>    Přílohy: <none>
>
> G> Sure, that will work, but what is the point?  That result map doesn't
> G> really buy you anything.  Why not just specify a resultType in your
> G> select instead of a resultMap?
>
> G> On 3/25/2010 7:43 AM, Tomáš Procházka wrote:
>
>>> I found solution i have this in xml mapping file
>
>>>   <resultMap type="java.lang.String" id="domainsResult">
>>>     <result property="" column="domain"/>
>>>   </resultMap>
>
>>> <select id="selectAvailableDomains" resultMap="domainsResult">
>>>   SELECT domain FROM queue WHERE ended IS NULL GROUP BY domain
>>> </select>
>
>>> and this in Mapper class
>
>>> List<String>  selectAvailableDomains();
>
>>> and it works
>
>
>>> ______________________________________________________________
>>>> Od: "Guy Rouillier"<[hidden email]>
>>>> Komu: [hidden email]
>>>> Datum: 24.03.2010 18:10
>>>> Předmět: Re: return simple String[] or List<String>
>
>>>> On 3/24/2010 10:30 AM, Tomáš Procházka wrote:
>
>>>>> It's possible return simple String[] or List<String>   with ibatis maping?
>
>>>> You don't mention which version of iBATIS you are using, so I'm assuming version 3.  This works:
>
>>>>      <select id="selectBundleId" resultType="string" parameterType="string">
>
>
>>>>> In documentation is only 'int' 'hashmap' and collection of own class.
>>>>> Itried resultType="java.util.String[]" or resultMap="java.util.String" and it doesn't work
>
>>>> The documentation says this: "Note that in the case of collections, this should be the type that the collection contains, not the type of the collection itself."  The type that the collection contains is string.
>
>>>> -- Guy Rouillier
>
>
>
>
>
> ------------------------ Konec původní zprávy ------------------------
>
> --
> ---------------------------------------------------------------------
>  Tomáš Procházka
>
>
>  E-mail: [hidden email]
>    WWW: http://www.atomsoft.cz
>    ICQ: 87147320
> ---------------------------------------------------------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: return simple String[] or List<String>

domi
This post has NOT been accepted by the mailing list yet.
In reply to this post by Tomáš Procházka-2
I'm trying to apply your solution to set property of pojo that declareing type is 'List<Integer>'('roles' as below), it magic works ! I hope somebody could found the solution. I have nearly worked around a whole day for this problem!

        <resultMap id="roleIds" type="java.lang.Integer">
                <result property="" column="roleId"/>
        </resultMap>
               
        <select id="getRoleIdsByUserId" resultMap="roleIds">
                SELECT PUR.role_id AS roleId
                FROM platform_user_role PUR
                WHERE PUR.user_id=#{userId}
        </select>

        <resultMap id="user" type="User">
                <id property="id" column="id"/>
                <result property="email" column="email"/>
                <result property="name" column="name"/>
                <result property="password" column="password"/>
                <result property="status" column="status"/>
                <association property="roles" column="id" select="getRoleIdsByUserId"/> 
        </resultMap>

        <select id="getUser" resultMap="user">
                SELECT
                        PU.id,
                        PU.email,
                        PU.name,
                        PU.password,
                        PU.status
                FROM platform_user PU
        <where>
                <if test="id!=null">
                AND PU.id=#{id}
                </if>
                <if test="email!=null">
                AND PU.email=#{email}
                </if>
        </where>
        </select>
Loading...