• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[hibernate] How to load lazy collections

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What technique do you use, when you need to access the lazy collections (those collections defined as lazy=true)?

Below is from hibernate document showing invalid access:



I am thinking of doing something like this. Do you do the same thing? Please show us, how you do it.

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the solution from hibernate forum:

Do something like:

=====================================
org.hibernate.Hibernate.initialize(permissions);
=====================================
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I follow your question. Hibernate will initialize your lazy collection when you access a property of that collection - why do you need to do it a different way?
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:I'm not sure I follow your question. Hibernate will initialize your lazy collection when you access a property of that collection - why do you need to do it a different way?


Outside of the transaction (detached), I will need to access the lazy ones.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. Typically if you know your code is going to use the collection you would initialize it in the session before you detach it, this saves you using Hibernate-specific code outside your DAO layer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic