Hibernate version: 3.2 cr3, svn snapshot: July 19, 2006
Name and version database: Oracle 10g
Hello, For several months I have been downloading and developing with latest svn snapshots of the release candidates of hibernate3, annotations, and entity manager.
If I use builds of code in the repository dated after 25-June-2006,
I have a problem with cglib proxy objects.
(If I rollback to the build of 25-June-2006, I don't experience the problem.)
I think the problem may be related to my use of InheritanceType.JOINED inheritance strategy -- PersonEJB is supclass / UserEJB is subclass -- and it's complications involving proxied objects.
However, I understood that a PersonEJB proxy is a subclass of PersonEJB. Given that, the error message below doesn't make sense to me.
HibernateException: instance not of expected entity type: com.blah.database.PersonEJB$$EnhancerByCGLIB$$1a73d941 is not a: com.blah.database.PersonEJB
The exception is thrown by the AbstractEntityPersister method (see code snippet below) because the value returned from getSubclassEntityName(clazz) == null,
where clazz is the PROXY. It does not seem correct that this method should be looking for the name of a proxy's subclass.
I am prepared to refactor my Person --> AuthenticatedUser (acegi artifact) -> User hierarchy to avoid using the JOINED inheritance type strategy and it's problems involving proxies, but this is a recent problem, and this code (below) and the error message does not make sense to me.
Could this method be incorrect?
Code:
public EntityPersister getSubclassEntityPersister(
Object instance,
SessionFactoryImplementor factory,
EntityMode entityMode) {
if ( !hasSubclasses() ) {
return this;
}
else {
// TODO : really need a way to do something like :
// getTuplizer(entityMode).determineConcreteSubclassEntityName(instance)
Class clazz = instance.getClass();
if ( clazz == getMappedClass( entityMode ) ) {
return this;
}
else {
String subclassEntityName = getSubclassEntityName( clazz );
if ( subclassEntityName == null ) {
throw new HibernateException(
"instance not of expected entity type: " + clazz.getName() +
" is not a: " + getEntityName()
);
}
else {
return factory.getEntityPersister( subclassEntityName );
}
}
}
}
Regards,
Stan