Collection/Association with annotations

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Collection/Association with annotations

Piotr Ponikowski
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Collection/Association with annotations

Guy Rouillier-2
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" <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/emadb6f3ae-8be5-4ccd-99c5-ddfc63dd58b3%40asus.
Reply | Threaded
Open this post in threaded view
|

Re: Collection/Association with annotations

Piotr Ponikowski
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.

sob., 30 lis 2019 o 07:43 Guy Rouillier <[hidden email]> napisał(a):
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" <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/emadb6f3ae-8be5-4ccd-99c5-ddfc63dd58b3%40asus.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CAH5y1XNbfPbj96St6Qo36EeNChM6odXeh3vKTeL%3Dk9nSpzKGqw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Collection/Association with annotations

Piotr Ponikowski
In reply to this post by Guy Rouillier-2
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" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="_AA7onDsAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">piotrpon...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_AA7onDsAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/5935f793-ac22-4875-af55-366361e9474a%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/134e2c5a-3516-4beb-8146-acfd12b16bfb%40googlegroups.com.