aspose file tools*
The moose likes Web Services and the fly likes JAXB+Hibernate=LazyInitializationException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAXB+Hibernate=LazyInitializationException" Watch "JAXB+Hibernate=LazyInitializationException" New topic
Author

JAXB+Hibernate=LazyInitializationException

stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
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

Joined: Oct 04, 2006
Posts: 2198
    
    1
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

Joined: Aug 17, 2009
Posts: 75
Thanks, but both approaches are all about loading entire objects and I cannot do that - it is very expensive operation.
michael cheung
Greenhorn

Joined: Apr 13, 2009
Posts: 3
You can also use Beanlib (http://beanlib.sourceforge.net/) to convert the hibernate persistence pojo back to your own dto.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAXB+Hibernate=LazyInitializationException