[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3019) LAZY 1:1 (self-) reference with Inheritance ---> WRONG INTERFACES implemented by Javassist/CGLIB created Proxies
S.Schnabl (JIRA)
noreply at atlassian.com
Tue Dec 18 11:12:56 EST 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29168 ]
S.Schnabl commented on HHH-3019:
--------------------------------
In class "org.hibernate.tuple.entity.AbstractEntityTuplizer" i found in the method "buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter)" the following code-snippet:
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 );
}
}
I don't understand, why we are even for the Inheritance-ROOT class are search for all sub(!)classes and put the subclass-interfaces to the interface-list, which we then store in the Proxy-Factory for the root-class. As a consequence, a proxy-object of type inheritance-root-entity will implement all interfaces of the subclasses - i think, this doesn't reflect the java inheritance idiom.
Please correct me, if i'm wrong.
> LAZY 1:1 (self-) reference with Inheritance ---> WRONG INTERFACES implemented by Javassist/CGLIB created Proxies
> ----------------------------------------------------------------------------------------------------------------
>
> Key: HHH-3019
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3019
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.4, 3.2.4.sp1, 3.2.5
> Environment: Win-XP, Jboss 4.2.2.GA, Java 1.6, Hibernate 3.2.4Sp1
> Reporter: S.Schnabl
> Priority: Blocker
> Attachments: Hibernate_lazy_1-to-1_with-proxy_TestCase.rar
>
>
> Hello, following simple testcase:
> EntityC, EntityB, EntityA are interfaces and have their respective implementations EntityCImpl, EntityBImpl, EntityAImpl. Inheritance structure is following:
> -> EntityC extends EntityB extends EntityA.
> Now EntityA has a 1:1 reference for another Entity, which at least must implement Interface 'EntityA' itself. These relation is described like following:
> @OneToOne(fetch = FetchType.LAZY, targetEntity = EntityAImpl.class)
> public EntityA getNextEntity() {
> return this.nextEntity;
> }
> Testcase: ( for complete testcase and entity structure see attached zip-file. Sorry, but only a jboss-variante attached due to short of time. Simply deploy the server.ear file from release-directory and run the src/client/TestCaseClient.java)
> Mainly the testcase does the following:
> // create a entityA
> EntityA a = new EntityAImpl();
> this.em.persist(a);
> // create a EntityB, which inherits from EntityA
> EntityB b = new EntityBImpl();
> this.em.persist(b);
> // link B to A
> a.setNextEntity(b);
> // load EntityA, which has an 1:1 attached EntityB(-Proxy!)
> EntityA a = this.em.find(EntityAImpl.class, idEntityA);
> // load attached EntityB - should be from expected type EntityB(-Proxy!)
> Object b = a.getNextEntity();
> // Now check, which Interfaces these EntityB implements: should be
> // EntityA and EntityB, but NOT EntityC
> if (b instanceof HibernateProxy)
> System.out.println("Loaded object is instanceof " + HibernateProxy.class.getSimpleName()); // true
> if (b instanceof EntityB)
> System.out.println("Loaded object is instanceof " + EntityBImpl.class.getSimpleName()); // true
> if (b instanceof EntityC)
> System.out.println("Loaded object is instanceof " + EntityCImpl.class.getSimpleName()); // TRUE - ERROR !!!!!!!! That's a bug ! We loaded an EntityB which CANNOT be of Type EntityC !!!!
> As you can see, the proxy implents wrongly the Interface EntityC, which must NOT implemented, cause we have only an EntityB linked to EntityA!!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list