-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Parent/child and inheritance
PostPosted: Thu Sep 02, 2004 10:10 am 
Beginner
Beginner

Joined: Thu Sep 02, 2004 9:17 am
Posts: 21
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 11:35 am 
Beginner
Beginner

Joined: Thu Sep 02, 2004 9:17 am
Posts: 21
Hi
I have found what appears to have been the problem.
I specified the database "dialect" incorrectly. Grr.
Now at least I am getting the results I expect.

Peter


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.