Returning several objects for single row

17 views
Skip to first unread message

jdevelop

unread,
May 5, 2013, 8:53:29 PM5/5/13
to mybatis-user
Hello!

I have several tables A, B, C, mapped to corresponding entities EA, EB
and EC.

I need to query the database with joining of these three tables,
having them to return 3 objects for each row (EA, EB, EC)

I know about associations, however there isn't much of "real" there. I
could create some fake class, which will contain all thee objects as
properties, but this is some artificial super-class case which I'd
like to avoid.

Please advice.

Guy Rouillier

unread,
May 5, 2013, 11:43:53 PM5/5/13
to mybati...@googlegroups.com
Return a hashmap.

--
Guy Rouillier

jdevelop

unread,
May 6, 2013, 10:30:41 AM5/6/13
to mybatis-user
The hashmap will return me all fields, which requires me to do the
binding later and wrap things manually, This is not much better than
doing plain JDBC call with PreparedStatement/ResultSet.

Larry Meadors

unread,
May 6, 2013, 10:32:38 AM5/6/13
to mybati...@googlegroups.com
No, I think he's saying use a map to contain your three classes that
you want back instead of creating a container class for them.

Larry

Frank Martínez

unread,
May 6, 2013, 10:35:30 AM5/6/13
to mybati...@googlegroups.com
The hashmap will containt just three properties, one for each class. The hashmap will act as your fake class. Just use a ResultMap to configure it. http://mybatis.github.io/mybatis-3/sqlmap-xml.html#Result_Maps



--
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 mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Frank D. Martínez M.

jdevelop

unread,
May 7, 2013, 12:56:06 PM5/7/13
to mybatis-user
Ok, thanks!

I found that if specify

<resultMap id="FoundUserMap" type="java.util.HashMap">
<association property="user"
resultMap="UserMap"
column="user_id"/>
<association property="oauth" resultMap="AnotherMap"
column="credentials_id"/>
</resultMap>

then it works well.

Thanks for advice!
Reply all
Reply to author
Forward
0 new messages