I am getting an error when building the session factory caused by the mapping document below. I am attempting to map a table per concrete class using union-subclass. The parent class is an interface and the subclasses implement that interface. They also extend another abstract class, so I cannot change the interface to an abstract class. The interface I reference as a field from another mapped class, so polymorphism is important.
The error is hibernate trying to find the id field on the interface. It looks for a superclass for the interface which returns null and throws the exception. It doesn't seem to realize this is an interface. I included the abstract="true" attribute but that doesn't make a difference.
I also tried implementing this as a table per class hiearchy using <subclass> and got the same error. From searching the forums, reference docs and Hibernate in Action, it would seem that one of these (or both) approaches should work, but I am not having any luck. I also can't find a complete working example anywhere that shows this type of inheritance mapping. The examples always seem to use concrete classes as the parent class. I've seen several similar posts that recommend using one of the approaches I have tried, but no reference to anyone getting this exception.
I've combed the forums, run through in the debugger, tried many different approaches without luck. I even tried implementing using <any> and it seemed to work in unit tests until integrated into my application then I ran into problems and I never liked that approach and see that it is not recommended.
Version Info: Hibernate Version 3.1 / Java JDK 1.5.0_06 / Oracle 10g
Mapping Doc:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="controlDomain" default-access="field" default-cascade="lock">
<class name="AnalysisResult" abstract="true">
<id name="id" column="ANALYSIS_ID" type="long">
<generator class="hibernateUtil.GeneratedIdentifierGenerator">
<param name="delegate">sequence</param>
<param name="sequence">ANALYSIS_ID_SEQ</param>
</generator>
</id>
<union-subclass name="AAnalysis" extends="AnalysisResult" table="A_ANALYSIS">
<many-to-one name="source" class="Source" column="SOURCE_ID"/>
...
</union-subclass>
<union-subclass name="BAnalysis" extends="AnalysisResult" table="B_ANALYSIS">
<many-to-one name="analysisType" class="AnalysisType" column="ANALYSIS_TYPE_ID"/>
<property name="analysisDateTime" column="ANALYSIS_DATE_TIME" type="timestamp"/>
...
</union-subclass>
</class>
</hibernate-mapping>
The Exception:
Code:
org.hibernate.PropertyNotFoundException: field not found: id
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:97)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:112)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:166)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:115)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:63)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
Debug level logging: no related log messages with debug turned up.
Related Code:
Code:
public interface AnalysisResult {
public int getExceptionCount();
public Long getId();
public Set<ExceptionItem> getExceptions();
...
}
public class AAnalysis extends AbstractGenericEntity<AAnalysis, Long> implements AnalysisResult {
...
}
public class BAnalysis extends AbstractGenericEntity<BAnalysis, Long> implements AnalysisResult {
...
}
public abstract class AbstractGenericEntity<E extends AbstractGenericEntity, K extends Serializable> {
private K id;
...
}
Let me know if any other information is needed. Would appreciate some assistance.
Regards,
Ken