Collection/Association with annotations

200 views
Skip to first unread message

Piotr Ponikowski

unread,
Nov 29, 2019, 5:09:17 PM11/29/19
to mybatis-user
Is it possible to use collections/assocations with annotation-based configuration?
For example can below mapping be converted to annotations?

<resultMap id="userMap" type="com.test.model.User">
<id column="id" property="id"/>
<result column="first_name" property="firstName"/>
<result column="last_name" property="lastName"/>
<collection property="roles" ofType="com.test.model.Role">
<result column="user_id" property="userId"/>
<result column="role_type" property="roleType"/>
</collection>
</resultMap>


Guy Rouillier

unread,
Nov 30, 2019, 1:44:01 AM11/30/19
to mybati...@googlegroups.com
Yes, see section 6, Mapper Annotations, in the MyBatis User Guide.  I just noticed there are a whole bunch of sections 6 (oops!); search for "Mapper Annotations", and then within that, take a look at the @Many annotation.

--
Guy Rouillier
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com.
Message has been deleted

Piotr Ponikowski

unread,
Nov 30, 2019, 4:03:24 AM11/30/19
to mybatis-user
My configuration for resultMap, extracts data from single query into result. I have forgot to include also example select:
<select id="getUsers" resultMap="userMap">
select * from test_user u
left join test_role r
on r.user_id = u.id
</select>
Thanks for poiting additional docs, it helped me to find notes for @One/@Many "NOTE You will notice that join mapping is not supported via the Annotations API. This is due to the limitation in Java Annotations that does not allow for circular references."

Unfortunately I cannot use single query to popullate hierarchy without additional selects for nested collections/associations, when using annotations.

W dniu sobota, 30 listopada 2019 07:44:01 UTC+1 użytkownik Guy Rouillier napisał:
Yes, see section 6, Mapper Annotations, in the MyBatis User Guide.  I just noticed there are a whole bunch of sections 6 (oops!); search for "Mapper Annotations", and then within that, take a look at the @Many annotation.

--
Guy Rouillier

On 11/29/2019 5:09:16 PM, "Piotr Ponikowski" <piotrpon...@gmail.com> wrote:

Is it possible to use collections/assocations with annotation-based configuration?
For example can below mapping be converted to annotations?

<resultMap id="userMap" type="com.test.model.User">
<id column="id" property="id"/>
<result column="first_name" property="firstName"/>
<result column="last_name" property="lastName"/>
<collection property="roles" ofType="com.test.model.Role">
<result column="user_id" property="userId"/>
<result column="role_type" property="roleType"/>
</collection>
</resultMap>


--
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 mybati...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages