-->
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: EnhancerByCGLIB vs POJO superclass mismatch
PostPosted: Thu Jul 20, 2006 3:00 pm 
Newbie

Joined: Wed Mar 08, 2006 10:33 pm
Posts: 16
Location: Brazil
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


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.