-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: How to avoid a "failed to lazily initialize a collectio
PostPosted: Fri Feb 01, 2008 7:20 pm 
Newbie

Joined: Fri Dec 21, 2007 11:09 pm
Posts: 9
Hi there,

I'm using JPA via the Hibernate EM to return the result of a query as a SOAP response. I'm naturally getting a "failed to lazily initialize a collection" type of exception when attempting to serialise my response given that my entity manager has been closed.

I'm wondering if there's a way of forcing a deep eager fetch on the result before I close my entity manager.

Oh, I should add that at the time that I make the request, it is unknown how deep the resultant object graph will be i.e. A may have a child B, which may have a child C, which may have a child D etc. This means that I don't know what to eagerly fetch in advance i.e. JOIN FETCH is probably not applicable?

I'm sure that this is JPA 101, so I apologise in advance for that. I'm kind-of stumped though.

Thanks for any help.

Cheers,
-C


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 03, 2008 5:43 am 
Newbie

Joined: Fri Dec 21, 2007 11:09 pm
Posts: 9
I've managed to figure this one out... if I serialise the object graph myself prior to closing the entity manager then I'm guaranteed that the graph has been entirely fetched. I can additionally pre-empt what will be lazily fetched with JOIN FETCH of course.

It'd be great for JPA to have a little more control over the fetch strategy on a dynamic basis... still, JPA/Hibernate rock!

Cheers,
-C


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 5:22 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You could use Hibernate.initialize(..).



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 10:34 pm 
Newbie

Joined: Fri Dec 21, 2007 11:09 pm
Posts: 9
Thanks for that - I was looking for a JPA style of answer but nonetheless appreciate your response.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 17, 2008 10:54 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
huntc wrote:
Thanks for that - I was looking for a JPA style of answer but nonetheless appreciate your response.



The problem here is that JPA does not cover everything. Therefore, you could expect to have vendor specific code here and there and that's fine. You would be able to replace vendor specific codes as the API evolves.


Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.