Hi,
In a particular parent-child use case, my object graph looks like this :
Code:
[ParentImpl] <implements> [ParentInterface]
[ChildInterface] <extends> [ParentInterface]
[ChildImpl] <extends> [ParentImpl], <implements> [ChildInterface]
While mapping them as hibernate entities, I had specified
"proxy=[ParentImpl]" for the parent class and
"proxy=[ChildInterface]" for the child one. However, this resulted in Hibernate cribbing
"org.hibernate.MappingException: proxy must be either an interface, or the class itself: [ChildImpl]". This looked strange since the proxy specified for child was indeed an interface (as mentioned above).
From the stack trace, I was able to get the piece of code that does this validation. Here is it, from
org.hibernate.tuple.PojoTuplizer.buildProxyFactory(...),with my comments added :
Code:
[...]
Class mappedClass = persistentClass.getMappedClass();
Class proxyInterface = persistentClass.getProxyInterface();
if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) {
if ( !proxyInterface.isInterface() ) {
throw new MappingException(
"proxy must be either an interface, or the class itself: " +
getEntityName()
);
}
proxyInterfaces.add( proxyInterface );
}
if ( mappedClass.isInterface() ) {
proxyInterfaces.add( mappedClass );
}
Iterator iter = persistentClass.getSubclassIterator();
while ( iter.hasNext() ) {
Subclass subclass = ( Subclass ) iter.next();
Class subclassProxy = subclass.getProxyInterface();
Class subclassClass = subclass.getMappedClass();
// *** [Vikas S] : This correctly checks subclassProxy ***
if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
// *** [Vikas S] : But why proxyInterface ??? Shouldn't this be subclassProxy ??? ***
if ( !proxyInterface.isInterface() ) {
throw new MappingException(
"proxy must be either an interface, or the class itself: " +
subclass.getEntityName()
);
}
proxyInterfaces.add( subclassProxy );
}
}
[...]
As mentioned in my inline comment, while iterating through the sub-class mappings it is validating
proxyInterface (proxy defined for parent) instead of
subclassProxy. Is this intended ??