Hibernate version:
3.2.0.cr4
Name and version of the database you are using:
HSQLDB 1.8
This is related to a post made by another user here:
http://forum.hibernate.org/viewtopic.php?t=981404&highlight=
Coding to interfaces, I have the following (a silly example, but the real example's more complex):
Code:
public interface SupportsTermination {
void setTermDate(Date date);
Date getTermDate();
}
public class Teacher implements SupportsTermination {
long id;
String name;
Date startDate;
Date endDate;
...
public void setTermDate(Date date){
this.endDate = date;
}
public Date getTermDate(){
return this.endDate;
}
}
public class Janitor implements SupportsTermination {
long id;
String name;
Date startDate;
Date endDate;
...
public void setTermDate(Date date){
this.endDate = date;
}
public Date getTermDate(){
return this.endDate;
}
}
My mapping for Teacher and Janitor would be:
Code:
<hibernate-mapping default-lazy="false" default-cascade="all">
<class name="com...Teacher"
table="teacher" lazy="false">
<id name="id" column="id" type="long">
<generator class="sequence">
<param name="sequence">teacher_seq</param>
</generator>
</id>
<property name="name" column="name" />
<property name="startDate" column="start_date"
type="date" />
<property name="endDate" column="end_date"
type="date" />
</class>
</hibernate-mapping>
<hibernate-mapping default-lazy="false" default-cascade="all">
<class name="com...Janitor"
table="janitor" lazy="false">
<id name="id" column="id" type="long">
<generator class="sequence">
<param name="sequence">janitor_seq</param>
</generator>
</id>
<property name="name" column="name" />
<property name="startDate" column="start_date"
type="date" />
<property name="endDate" column="end_date"
type="date" />
</class>
</hibernate-mapping>
The idea being that a termination service would be able to perform terminations for any type that implements TerminationAware.
I initially intended to utilize implicit polymorphism, expecting that the following query might work (I'm using Spring's HibernateTemplate) without any additional mapping:
Code:
List<TerminationAware> terms = this.hibernateTemplate
.find("from TerminationAware");
But I get the following error message:
Quote:
org.hibernate.hql.ast.QuerySyntaxException: TerminationAware is not mapped [from TerminationAware]
So it seems some mapping is necessary. I've read over this section of the reference manual
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance-strategies several times, but I'm still unclear on how to map this interface.
Any suggestions would be greatly appreciated!
Thanks,
Leo