How to avoid mybatis lazy fetch when spring copy beans' properties?

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

How to avoid mybatis lazy fetch when spring copy beans' properties?

mfemilu



For example:

Mapper.xml

<resultMap type="com.sin.sys.domain.dto.UserDTO" id="baseResultMap">
<id property="id" column="id" />
<result property="createdTime" column="created_time" />
<result property="updatedTime" column="updated_time" />
<result property="optUserId" column="opt_user_id" />
<result property="isDeleted" column="is_deleted" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="email" column="email" />
<result property="cellPhone" column="cell_phone" />
<result property="nickname" column="nickname"/>
<collection property="User2groupKeyDTOList" 
ofType="com.sin.sys.domain.dto.User2groupKeyDTO"
column="{sysUserId=id}" select="com.sin.sys.mapper.user2group.User2groupKeyMapper.selectOne">
</collection>
</resultMap>


UserService do like follow:

User user = userService.getById();

User tempUser = new User();

//this step will execute lazy fetch sql,  But I don't hope to execute these lazy sql
BeantUtils.copyproerties(user,tempUser)


Is there some way can avoid this?

One solution is set properties by hand one by one, but code is too loog.
Is there any short code solution?










--
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: How to avoid mybatis lazy fetch when spring copy beans' properties?

Iwao AVE!
Hi,

Lazy property is loaded when the getter method or one of the lazyLoadTriggerMethods is called.
So, you should look for a way to copy properties without invoking these methods.

It seems that copyProperties() method can take field names to ignore.
Have you tried that?

Regards,
Iwao

2017-03-26 19:19 GMT+09:00 <[hidden email]>:



For example:

Mapper.xml

<resultMap type="com.sin.sys.domain.dto.UserDTO" id="baseResultMap">
<id property="id" column="id" />
<result property="createdTime" column="created_time" />
<result property="updatedTime" column="updated_time" />
<result property="optUserId" column="opt_user_id" />
<result property="isDeleted" column="is_deleted" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="email" column="email" />
<result property="cellPhone" column="cell_phone" />
<result property="nickname" column="nickname"/>
<collection property="User2groupKeyDTOList
ofType="com.sin.sys.domain.dto.User2groupKeyDTO"
column="{sysUserId=id}" select="com.sin.sys.mapper.user2group.User2groupKeyMapper.selectOne">
</collection>
</resultMap>


UserService do like follow:

User user = userService.getById();

User tempUser = new User();

//this step will execute lazy fetch sql,  But I don't hope to execute these lazy sql
BeantUtils.copyproerties(user,tempUser)


Is there some way can avoid this?

One solution is set properties by hand one by one, but code is too loog.
Is there any short code solution?


--
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: How to avoid mybatis lazy fetch when spring copy beans' properties?

Guy Rouillier-2
In reply to this post by mfemilu
I see Iwao already replied.  But I'm confused as to what you wish to accomplish.  How do you think you can copy all the properties without fetching them?

--
Guy Rouillier



------ Original Message ------
To: "mybatis-user" <[hidden email]>
Sent: 3/26/2017 6:19:10 AM
Subject: How to avoid mybatis lazy fetch when spring copy beans' properties?




For example:

Mapper.xml

<resultMap type="com.sin.sys.domain.dto.UserDTO" id="baseResultMap">
<id property="id" column="id" />
<result property="createdTime" column="created_time" />
<result property="updatedTime" column="updated_time" />
<result property="optUserId" column="opt_user_id" />
<result property="isDeleted" column="is_deleted" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="email" column="email" />
<result property="cellPhone" column="cell_phone" />
<result property="nickname" column="nickname"/>
<collection property="User2groupKeyDTOList" 
ofType="com.sin.sys.domain.dto.User2groupKeyDTO"
column="{sysUserId=id}" select="com.sin.sys.mapper.user2group.User2groupKeyMapper.selectOne">
</collection>
</resultMap>


UserService do like follow:

User user = userService.getById();

User tempUser = new User();

//this step will execute lazy fetch sql,  But I don't hope to execute these lazy sql
BeantUtils.copyproerties(user,tempUser)


Is there some way can avoid this?

One solution is set properties by hand one by one, but code is too loog.
Is there any short code solution?










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

Virus-free. www.avast.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].
For more options, visit https://groups.google.com/d/optout.
Loading...