The problem, I have is the following:
In a single table inheritence model, the actual implementations should be proxied by an interface.
Code:
@Entity
@Table(name="FOO")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE",discriminatorType=DiscriminatorType.STRING)
public abstract class AbstractFoo {
...
}
Code:
@Entity
@Proxy(proxyClass=Foo.class)
@DiscriminatorValue("DEFAULT")
public class FooImpl extends AbstractFoo implements Foo {
...
}
Mapping this I get the following exception:
Code:
Caused by: org.hibernate.MappingException: proxy must be either an interface, or the class itself: com.dummy.FooImpl
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:121)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
And I think there is a copy and paste error in the PojoEntityTuplizer causing this (line 120).
Code:
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();
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 think the check on being an interface must be on the subclassProxy and not on the proxyInterface (which is in this case the abstract superclass).
Is this a bug?
Cheers
Hansa