Hi there
I am having trouble implementing a parent/child relationship, which involves inheritance.
Hibernate version: 2.1.6
Database: hypersonic
I have three classes:
A couple of abstract classes:
"Base" class which contains an id;
"Node" class which represents a node in a tree structure (with a reference to its parent);
and a concrete "Department" class which extends the abstract Node class.
public abstract class AbstractBase.
public abstract class AbstractNode extends AbstractBase
public class Department extends AbstractNode
Eventually I want several different types of concrete classes.
I have these database tables:
BASE
NODE
DEPARTMENT
corresponding to the abovementioned classes.
How can I save/retrieve my concrete class hierarchies in a database with Hibernate?
At the moment I am trying a mapping like this, but get weird SQL exceptions, so I am obviously doing something completely wrong....
java.sql.SQLException: Unexpected token: ABSTRACTNO0__2_.ID in statement [select abstractno0_.ID as ID0_, case when abstractno0__2_.ID is not null then 1 when abstractno0_.ID is not null then 0 end as clazz_0_, abstractno0_.PARENT_ID as PARENT_ID1_0_, abstractno0__2_.NAME as NAME2_0_ from NODE abstractno0_ inner join BASE abstractno0__1_ on abstractno0_.ID=abstractno0__1_.ID left outer join DEPARTMENT abstractno0__2_ on abstractno0_.ID=abstractno0__2_.ID where abstractno0_.ID=1]
<hibernate-mapping>
<class name="dk.peter.common.AbstractBase" table="BASE" >
<id name="id" type="long" column="ID">
<generator class="increment"/>
</id>
<joined-subclass name="dk.peter.common.AbstractNode" table="NODE">
<!-- Points to AbstractBase. -->
<key column="ID" />
<many-to-one name="parent" column="PARENT_ID" class="dk.peter.common.AbstractNode" />
<joined-subclass name="dk.peter.company.Department" table="DEPARTMENT">
<!-- Points to AbstractNode. -->
<key column="ID" />
<property name="name" column="NAME" type="string" />
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>
Thanks for any help,
Peter
|