Hello, I found a problem in LAZY 1:1 relationship, if the toOne-Side is part of a inheritance-structure. In such a case, the Javassist/Cglib created proxy will implement wrong interfaces!
See 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:
Code:
@OneToOne(fetch = FetchType.LAZY, targetEntity = EntityAImpl.class)
public EntityA getNextEntity() {
return this.nextEntity;
}
Mainly the testcase does the following:
Code:
// 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!!
Opened
JIRA-3019
Any Ideas ??