简体   繁体   中英

Same object is fetched as Lazy when available in nested hierarchy

Scenario - User table contains createdBy (userId) column which is lazy loaded.

When I fetch the list of users, some objects show as lazy into the main list of user's fetched. When I checked, found that objects which are loaded lazily are present as createdBy (lazily loaded) into some other user object into the main list.

I have attached screenshots to explain in more detail. The first screenshot shows created by as a user object (lazy). The second screenshot shows same user object as lazy even though when it is under the main list of user's fetched.-------1st image----- Lazy nested object as createdBy -----2 nd image ----- lazy main object when the same object is lazy in nested one Please help.

what happen is lets say i have 3 users is my table named A,B and C. A is created by B. while Now User object have createdBy field which is lazy loaded. When i fetch my users from DB using hibernate, I get user A (actual object), B(lazy object), C(actual object). When i checked i found I get B as lazy bcoz B is also present in Object A as createdBy Field and it is lazy there.

What's issue ??

When Entities are loaded in lazy format. you will only see min detail like in img 1, UserId. If you see inside User object like in img 2, all values are null because they are bound to lazy loading.

In lazy loading values are loaded only when used.

eg. you can use user.getAccesstoken and you will see value of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM