-->
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.  [ 4 posts ] 
Author Message
 Post subject: Interceptor instanciated instances do not have an id
PostPosted: Wed Jun 03, 2009 8:25 am 
Newbie

Joined: Wed Jun 03, 2009 8:11 am
Posts: 1
I defined an interceptor to redifine object instantiation, overriding the interceptor.instantiate( ).
I noticed that the id is not set on the object after the instantiation.

So i modified SessionImpl the following way, which works right for my use case:

Code:
   /**
    * give the interceptor an opportunity to override the default instantiation
    */
   public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException {
      errorIfClosed();
      checkTransactionSynchStatus();
      Object result = interceptor.instantiate( persister.getEntityName(), entityMode, id );
      if ( result == null ) {
         result = persister.instantiate( id, entityMode );
      }
      // set the id for object instanciated an interceptor
      else {
         persister.setIdentifier(result, id, entityMode);
      }
      return result;
   }


Why the instantiate method forces the developer to override both object instantiation and id generation ?

Shouldn't there be two separate methods to override ?


Thanks in advance


Top
 Profile  
 
 Post subject: Re: Interceptor instanciated instances do not have an id
PostPosted: Mon Nov 01, 2010 10:34 am 
Newbie

Joined: Tue Sep 02, 2003 10:35 pm
Posts: 9
This seems like a very reasonable change to the SessionImpl because it knows how to set the identifier, where as that information is not provided in the Interceptor.instantiate() method.


Top
 Profile  
 
 Post subject: Re: Interceptor instanciated instances do not have an id
PostPosted: Mon Dec 13, 2010 7:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Jan 23, 2006 9:18 pm
Posts: 14
Would using a custom EntityPersister instead solve your problem?


Top
 Profile  
 
 Post subject: Re: Interceptor instanciated instances do not have an id
PostPosted: Tue Dec 14, 2010 6:14 am 
Newbie

Joined: Tue Sep 02, 2003 10:35 pm
Posts: 9
gbadner wrote:
Would using a custom EntityPersister instead solve your problem?


Gail, I'm not sure I can see how a custom EntityPersister would have helped here because the interceptor is doing the instantiation and it doesn't have access to the EntityPersister in order to assist with instantiating the object and making sure the identifier is set. Please can you explain what you're thinking is here?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.