nested select

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

nested select

somid3
I am having trouble performing a one-to-one nested select. I have a "Content" and a "User" object. A Content is created by a User.

<resultMap id="contentResultMap" type="Content">
<id property="id" column="id" />
<result property="createdOn" column="created_on"/>
<result property="content" column="content"/>
<association property="createdByUser" column="created_by_user_id" select="com.moesjokes.domain.User.selectById" />
</resultMap>

<select id="com.moesjokes.domain.Content.selectById" parameterType="int" resultType="Content">
select * from contents where id = #{id}
</select>

---------

<resultMap id="userResultMap" type="User">
<id property="id" column="id" />
<result property="createdOn" column="created_on"/>
<result property="emailAddress" column="email_address"/>
</resultMap>

<select id="com.moesjokes.domain.User.selectById" parameterType="int" resultType="User">
select * from users where id = #{id}
</select>

When I call com.moesjokes.domain.Content.selectById and, on the resulting Content call: content.getCreatedByUser() I get a NPE.

What other source code or documents can I show you to debug this more efficiently?

Two side questions:
1. Does the same SqlSession need to be used when I call content.getCreatedByUser(), or can I lazily load the User who created the content from within a different session.
2. Where do I define the aggresizeLazyLoading feature?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: nested select

somid3
ops, I also tried: <association property="createdByUser" column="created_by_user_id" javaType="com.moesjokes.domain.User" select="com.moesjokes.domain.User.selectById" /> 
Reply | Threaded
Open this post in threaded view
|

Re: nested select

somid3
for future searches refer to: https://groups.google.com/d/topic/mybatis-user/-z9TKJC5TnE/discussion
Reply | Threaded
Open this post in threaded view
|

Re: nested select

Jackie Li
Hi,

I suggest you give more logs, which would be more helpful for others offering help.

Besides, what's the attibute type of "createdByUser", is it a user object?

Cheers,
Jackie


On Tue, Mar 29, 2011 at 08:49, somid3 <[hidden email]> wrote:
for future searches refer to: https://groups.google.com/d/topic/mybatis-user/-z9TKJC5TnE/discussion

Reply | Threaded
Open this post in threaded view
|

Re: nested select

somid3
Hi,

What do you mean by "more logs"?

Yes, "createdByUser" is an Object of type User
Reply | Threaded
Open this post in threaded view
|

Re: nested select

Jackie Li
Hi,

I'd like to try to help. But so far the error statement is only
When I call com.moesjokes.domain.
Content.selectById and, on the resulting Content call: content.getCreatedByUser() I get a NPE. which means content is null.

Your XMLs seems fine, except like you said is your latest reply, resultMap is more favoriable than resultType. So after you change to "resultMap", it works?


Cheers,
Jackie


On Tue, Mar 29, 2011 at 11:02, somid3 <[hidden email]> wrote:
Hi,

What do you mean by "more logs"?

Yes, "createdByUser" is an Object of type User

Reply | Threaded
Open this post in threaded view
|

Re: nested select

somid3
Oh yeah, its working great, im flying in my ibatis heaven right now =)