-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate, PojoEntityTuplizer : Subclass and Proxy
PostPosted: Mon Jun 18, 2007 4:18 am 
Newbie

Joined: Sat Dec 03, 2005 5:35 am
Posts: 11
Hi,

I use Hibernate and JBPM, here is my architecture :
java : sequenceNode inherited from node
hbm : sequenceNode mapped as subclass of node with discriminator and a proxy (to enable cast). node as declared in JBPM.

I had an exception when initializing hibernate.
MappingException("proxy must be either an interface, or the class itself: SequenceNode)

After debug :
SequenceNode with its proxy is well initialized
Node without declared proxy launch an exception.

I saw in PojoEntityTuplizer.java (the class that launch an exception) the following code in buildProxyFactory() :

Code:
      Iterator iter = persistentClass.getSubclassIterator();
      while ( iter.hasNext() ) {
         Subclass subclass = ( Subclass ) iter.next();
         Class subclassProxy = subclass.getProxyInterface();
         Class subclassClass = subclass.getMappedClass();
         if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
            if ( !proxyInterface.isInterface() ) {
               throw new MappingException(
                       "proxy must be either an interface, or the class itself: " +
                       subclass.getEntityName()
               );
            }
            proxyInterfaces.add( subclassProxy );
         }
      }


Why do hibernate test proxyInterface.isInterface() instead of subclassProxy.isInterface() ? Indeed, this is the subclassProxy which is added.

Actually I can't cast a node$$EnhancedByCGlib to a sequenceNode.
(I don't have access at the session object when I want to cast)

Any clue for me ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 9:26 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
Quote:
Why do hibernate test proxyInterface.isInterface() instead of subclassProxy.isInterface() ? Indeed, this is the subclassProxy which is added.

Seems for me like a bug too. Think a JIRA-Entry should be opened ?

BTW: I don't understand the whole code snippet:

Code:
      Iterator iter = persistentClass.getSubclassIterator();
      while ( iter.hasNext() ) {
         Subclass subclass = ( Subclass ) iter.next();
         Class subclassProxy = subclass.getProxyInterface();
         Class subclassClass = subclass.getMappedClass();
         if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
            if ( !proxyInterface.isInterface() ) {
               throw new MappingException(
                       "proxy must be either an interface, or the class itself: " +
                       subclass.getEntityName()
               );
            }
            proxyInterfaces.add( subclassProxy );
         }
      }


This code results in an Proxy-Object, that implements ALL Interfaces of all of the subclasses. That's, in my opinion, inheritance "in the wrong direction". See also JIRA-3019 and Forum.

Quote:
Actually I can't cast a node$$EnhancedByCGlib to a sequenceNode.

See Documentation. The Proxy-object of your entity has only the interfaces, but is not of real entity-type. Therefore you cannot cast the proxy to the entity.


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