-->
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.  [ 3 posts ] 
Author Message
 Post subject: Interceptor.instantiate & setting the identifier
PostPosted: Tue Aug 03, 2004 2:13 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
I just ran into the issue with my custom Interceptor....

After browsing through the source code I noticed that with SessionImpl.java has the following instantiate method:

public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException {
Object result = interceptor.instantiate( persister.getEntityName(), id );
if ( result == null ) result = persister.instantiate( id );
return result;
}

This is great that I can create my own intantiate my the type of object that I need, but it does not allow me to set the identifier in a flexible manner.

Is there a reason why just the entityName is being passed into the interceptor's instantiate method and not the entire persister. The argument I make for doing the latter is that it allows you access to the setter that one defines for the identifier in the mapping file. Another alternative to this would be to introduce a new interceptor method, "setIdentifier(...)" that would allow you do such a thing.

The javadoc should be updated if the interceptor is expected to set the identifier for the new object being created in this method.

-------------------------------------
Mapping File
-------------------------------------
<dynamic-class entity-name="category" table="categories">
<id name="id" column="id" type="long" unsaved-value="0" access="org.progeeks.meta.hibernate.MetaObjectAccessor">
<generator class="native">
<param name="sequence">category_seq</param>
</generator>
</id>

<property name="parent CategoryId"
column="parent_category_id"
type="long"
insert="true"
update="true"
access="org.progeeks.meta.hibernate.MetaObjectAccessor"/>

many more properties defined in a similar way
</dynamic-class>

-------------------------------------
Custom Interceptor -- ( Implemented methods )
-------------------------------------
public class MetaObjectInterceptor implements Interceptor {

public Object instantiate( String name, Serializable serializable ) throws CallbackException
{
MetaClass metaClass = MetaClass.forName( name );
MetaObjectFactory factory = metaKit.getMetaObjectFactory();
MetaObject metaObject = factory.createMetaObject( metaClass );

return metaObject;
}

public String getEntityName( Object o ) throws CallbackException
{
MetaObject metaObject = ( MetaObject ) o;
return metaObject.getMetaClass().getName();
}
}

_________________
Matt Veitas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Don't crosspost.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 2:26 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
I apologize for the cross post...

Any words of wisdom or thoughts on the subject?

_________________
Matt Veitas


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