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
~
|