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