If you implement net.sf.hibernate.Interceptor, your implementation of the instantiate method must set the id of the object it returns (if it returns an object). The id is passed to instantiate, as a Serializable parameter.
I neglected to set the id in my implementation of Interceptor.instantiate. I saw no ill effect with Hibernate 2.0.2. But when I attempted to upgrade to Hibernate 2.0.3 or 2.1 beta 3b, mysterious errors occurred (some of which I reported as HB-367 in JIRA). The errors stopped after I changed instantiate to work like this:
Code:
public Object instantiate(Class clazz, Serializable id) throws CallbackException
{
Object entity = null; // let Hibernate instantiate something, by default
try {
entity = clazz.newInstance();
} catch(Exception e) {}
if (entity instanceof Identifiable) { // an application-defined interface
((Identifiable)entity).setIdentifier(id);
}
return entity;
}
Critique and better ideas are welcome.