-->
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.  [ 1 post ] 
Author Message
 Post subject: Possible bug in org.hibernate.engine.ForeignKeys.java
PostPosted: Thu May 08, 2008 5:09 am 
Newbie

Joined: Thu May 08, 2008 4:45 am
Posts: 1
Location: Barcelona
When Hibernate determines whether it should null out references to associated entities, it checks if the entity is wrapped in a proxy.

Code:
if ( object instanceof HibernateProxy ) {
   // if its an uninitialized proxy it can't be transient
   LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
   if ( li.getImplementation(session) == null ) {
      return false;
      // ie. we never have to null out a reference to
      // an uninitialized proxy
   }
   else {
      //unwrap it
      object = li.getImplementation();
   }
}


In case the proxy has not been initialized, Hibernate decides there is no need to null out the reference. It does the check by calling getImplementation(session) which checks if the entity is available in the current persistentContext. If that code succeeds, Hibernate decides to unwrap the proxy, but at that time it calls getImplementation() without session, which tries to actually initialize the proxy. And that will fail if the proxy has been detached.

In my opinion, there should be no call to getImplementation().
I suggest the following correction:

Code:
if ( object instanceof HibernateProxy ) {
   // if its an uninitialized proxy it can't be transient
   LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();

   //TODO fix: never call getImplementation() without session, since it would try to initialize the proxy
   Object implementation = li.getImplementation(session);
   if (implementation == null) {
      return false;
      // ie. we never have to null out a reference to
      // an uninitialized proxy
   }
   else {
      //unwrap it
      object = implementation;
   }
}


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

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.