-->
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: beware: Interceptor.instantiate must set id
PostPosted: Wed Oct 01, 2003 8:52 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 4:17 pm
Posts: 27
Location: California, USA
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.


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.