-->
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: Does Hibernate exception remove managed collection objects?
PostPosted: Thu Jun 22, 2006 11:06 am 
Newbie

Joined: Thu Jun 22, 2006 10:54 am
Posts: 1
I'm but a student of Hibernate and its EJB3 incarnation. This situation was related to me by some dissatisfied user, and I'm trying to understand if his situation relates to Hibernate behavior or to his misunderstanding of Hibernate. I suspect that this person was using Hibernate 2.x.

This person said he acquired Java code references to data managed through a lazy-fetched collection. For example, if Employee has a collection phones that is lazy-fetched, suppose the program has a global List named empphones that points at the collection:

empphones = employee.getPhones().

empphones points at a List containing Hibernate proxies. Assume that there are multiple phone numbers available.

Now suppose that the first phone number (out of 3) is actually fetched (or iterated to). So the collection from getPhones() has one instantiation and two proxies.

During some point in working with employee Hibernate throws an exception. This person I was speaking to insists that *any* exception causes his problems. I understand that the Hibernate Session, and EJB3 EntityManager, are now invalid. But what about the collection pointed to by empphones? The [1] and [2] elements weren't fetched. Do they point at proxies or at null? The [0] element was instantiated. Does it point at a Phone object, or a proxy that can still be accessed for its values, or at a proxy that throws exceptions, or at null?

And what about the employee object itself? Since it was managed (obtained through a call to Hibernate) is it still usable in the Java program for use during building the next Session/EntityManager or is it somehow invalid/null? The manual says it should be available, but this person makes me think otherwise.

Thanks in advance for help,

Jerome Mrozak


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 7:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Assuming that the offending exception was caught, and the relevant session was cleaned (closed, optionally reconnected), then the results should be:
  • The Employee object, excluding still-proxied assocations/collections, is still ok to use.
  • Ditto for empphones[0].
  • empphones[1] and [2] will be proxied objects: using any of their fields will cause a CGLib exception.
No objects that were non-null while the session was valid will be set to null, or anything like that. The only difference between before and after the hibernate exception is that accessing still-proxied objects will cause a CGLib exception.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Just to clarify
PostPosted: Fri Jun 23, 2006 1:08 pm 
Newbie

Joined: Fri Jun 23, 2006 12:52 pm
Posts: 11
I am the user of Hibernate that JavaGuy is referring to. Here is my reply to him via email:

The reply is correct, but this state is far from useful. You can't use the iterator, nor is get safe and most of the collection operations might throw exceptions depending on the use. Essentially the collection is worthless because you have no idea at which point the collection with throw an exception.

------------------------------
Brian Pontarelli
Director of Technology
Naymz


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.