This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB+Hibernate=LazyInitializationException

 
stanislav bashkirtsev
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have mapped class that has lazy-fields. I retrieve object of this class from DB and close hibernate session. But I also use JAXB, that serializes object and tries to access the lazy collection. So I get LazyInitializationException.
How can I solve this problem?
Thanks.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Possible approaches:
1. Use JAXB to serialize BEFORE you close the Hibernate session.
2. Make sure that Hibernate has loaded the entire object graph that is to be serialized by JAXB BEFORE closing the Hibernate session.
Best wishes!
 
stanislav bashkirtsev
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but both approaches are all about loading entire objects and I cannot do that - it is very expensive operation.
 
michael cheung
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use Beanlib (http://beanlib.sourceforge.net/) to convert the hibernate persistence pojo back to your own dto.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic