-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can a collection with fetch join containing proxy objects?
PostPosted: Tue Apr 26, 2005 2:32 pm 
Beginner
Beginner

Joined: Thu Jun 24, 2004 1:04 pm
Posts: 35
Location: Minnesota - USA
Been a while since I posted on the forums, Hibernate's been working great for us, and we've been able to address any issues ourselves. However, once in a blue moon one of our developers will come to me with an interesting behaviour they are seeing. Specifically, some of the objects in a collection attribute loaded using a 'join fetch' throw LazyInitialization exception when accessed on the web tier (Session long since closed). The strange thing, is that sometimes the same query will work and at other times it will not.

Today I encountered the same behaviour myself, luckily with only two HQL having been run! The 2nd HQL being the one that returns the results we want to use.

The tables structure is of the general form:

A <--> B (one to many)
B <--> C (one to many)

Relationships are setup in a bi-directional fashion and everything is proxy-able.

The first HQL queries objects C, _without_ fetching B. This results with C having a non-initialized proxy to B.

The second HQL queries objects A, _with_ fetching B. This results with A having an initialized collection of B objects.

What I notice then, is that some of the B in the collection from the 2nd query are actually non-initialized proxy objects. It seems to me the first query is loading a non-initialized proxy into the Session, that is then being placed into the collection fetched by the second query.

Note: If I do not run the first query, all objects in the second query are initialized.

My ultimate question then is: Does a fetch join only guarentee the Collection is initialized, but not that the objects in the collection are initialized? (even though the fetch loads the data needed initialized the objects)

I've searched the forums, scanned the documentation and my HiA, and I've not hit upon the magic answer yet. Best I reference I found was something by Max at the end of this post, but I was unable to find the comment in the javadoc he says he added.
http://forum.hibernate.org/viewtopic.php?t=935226&highlight=fetch+join+initialization+proxy+lazy

Humble apologies if this is answered elsewhere. I've not found it in any form that I recognized. It's not for lack of trying. I'm posting as a last resort.

Later,
gus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 2:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, this is the behavior in 2.1.x. Hibernate3 has the behavior you are looking for.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 3:22 pm 
Beginner
Beginner

Joined: Thu Jun 24, 2004 1:04 pm
Posts: 35
Location: Minnesota - USA
Thanks for the clarification Gavin!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.