-->
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.  [ 1 post ] 
Author Message
 Post subject: tree mapping
PostPosted: Sat May 19, 2007 8:48 am 
Newbie

Joined: Mon Aug 08, 2005 8:33 am
Posts: 7
I am not quite sure how to map a recursive tree class that looks like this.

class TreeItem {

int id; // identifier
String name;
TreeItem parent[];

...
}

The database schema I want to generate should lhave 2 tables. One table that holds each TreeItem and another called TreeParent which contains the ids of a TreeItem's parent(s):

create Table TreeItem
{
id integer not null auto_increment,
name varchar(255),
primary key (id)
}

create Table TreeParent
{
id integer not null,
idx integer, // parent sort order
parentId integer, // parent id
primary key (id)
}

I have tried this mapping file:

<hibernate-mapping>

<class name="TreeItem" table="TreeItem">

<id name="id" type="int">
<generator class="identity"/>
</id>

<property name="name" type="java.lang.String"/>

<array name="parent" table="TreeParent">
<key column="parentId"/>
<index column="idx"/>
<one-to-many class="TreeItem"/>
</array>

</class>

</hibernate-mapping>

This mapping file just generates one table which is clearly not right:

create table TREEITEM (
id integer not null auto_increment,
name varchar(255),
parentId integer,
idx integer,
primary key (id)
)

James

~


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

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.