Quantcast

Map multiple column from single query to list

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

Map multiple column from single query to list

Vang Yang
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

vl cheong
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

Vang Yang
Hello, 

I'm afraid the sql can't be changed.  It must return the columns as specified.

On Tuesday, February 28, 2017 at 6:29:36 PM UTC-6, vl cheong wrote:
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

Frank Martínez
You can use constructor mapping and populate the child list with any attributes you want.

El 28/02/2017 9:29 PM, "Vang Yang" <[hidden email]> escribió:
Hello, 

I'm afraid the sql can't be changed.  It must return the columns as specified.

On Tuesday, February 28, 2017 at 6:29:36 PM UTC-6, vl cheong wrote:
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

vl cheong
In reply to this post by Vang Yang
If you can't change the sql, then try using this List<Map<String, String>>. The key will be the column name and the value is the column value.

On Wednesday, March 1, 2017 at 10:29:46 AM UTC+8, Vang Yang wrote:
Hello, 

I'm afraid the sql can't be changed.  It must return the columns as specified.

On Tuesday, February 28, 2017 at 6:29:36 PM UTC-6, vl cheong wrote:
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

Vang Yang
In reply to this post by Frank Martínez
Thanks, will try that. But I was, hopefully, looking for something along the lines of <collection>.

On Tuesday, February 28, 2017 at 8:45:21 PM UTC-6, Frank Martinez wrote:
You can use constructor mapping and populate the child list with any attributes you want.

El 28/02/2017 9:29 PM, "Vang Yang" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="z031sYIpDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vpyan...@...> escribió:
Hello, 

I'm afraid the sql can't be changed.  It must return the columns as specified.

On Tuesday, February 28, 2017 at 6:29:36 PM UTC-6, vl cheong wrote:
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="z031sYIpDwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

Vang Yang
In reply to this post by vl cheong
Interesting, might have to try this. Though it does change my object entity, making list more complex than it needs to be. Might you give an example?

On Wednesday, March 1, 2017 at 2:46:29 AM UTC-6, vl cheong wrote:
If you can't change the sql, then try using this List<Map<String, String>>. The key will be the column name and the value is the column value.

On Wednesday, March 1, 2017 at 10:29:46 AM UTC+8, Vang Yang wrote:
Hello, 

I'm afraid the sql can't be changed.  It must return the columns as specified.

On Tuesday, February 28, 2017 at 6:29:36 PM UTC-6, vl cheong wrote:
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map multiple column from single query to list

vl cheong
<select id="xxx"
       
resultType="hashmap">
    SELECT
        addr1,
        addr2,
        addr3
    FROM
        table
</select>



On Thursday, March 2, 2017 at 12:18:09 AM UTC+8, Vang Yang wrote:
Interesting, might have to try this. Though it does change my object entity, making list more complex than it needs to be. Might you give an example?

On Wednesday, March 1, 2017 at 2:46:29 AM UTC-6, vl cheong wrote:
If you can't change the sql, then try using this List<Map<String, String>>. The key will be the column name and the value is the column value.

On Wednesday, March 1, 2017 at 10:29:46 AM UTC+8, Vang Yang wrote:
Hello, 

I'm afraid the sql can't be changed.  It must return the columns as specified.

On Tuesday, February 28, 2017 at 6:29:36 PM UTC-6, vl cheong wrote:
Hi,
Try to rewrite your SQL like this
SELECT addr1 AS addr FROM TABLE
    UNION ALL
SELECT addr2 AS addr FROM TABLE
   UNION ALL
SELECT addr3 AS addr FROM TABLE




On Wednesday, March 1, 2017 at 6:57:36 AM UTC+8, Vang Yang wrote:
Hello,

Is there a way to map multiple columns from a query to a single list? For example, my query returns something like addr1, addr2, addr3 and I'd like to map that to my java list List<String>. I've tried using the <collection> for resultmap but that doesn't seem to be working.

Any help on this matter is much appreciated.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...