-->
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: Mapping a nested object tree with an external table.
PostPosted: Mon Dec 06, 2004 7:31 pm 
Newbie

Joined: Mon Sep 29, 2003 11:14 am
Posts: 6
I'm posting this to get some insight on how I can approach this - to have a nested tree-type structure for our objects (in our case, a Topic) which we have set up a bit differently than most examples I am able to find on this site.

I've looked up the reference guide for the parent/child relationship in a single table in the hibernate reference documentation, and most examples in there assume that the table containing the domain object will also have a PARENT_ID column, but we are attempting to keep the tree structure information, in this case, PARENT_ID separate from the actual topic table itself.

So we have a TOPIC table and a TOPIC_TREE table, and two corresponding classes, the Topic class and TopicTree class.

TOPIC
=====
TOPIC_ID

TOPIC_TREE
=========
TOPIC_TREE_ID
TOPIC_ID
PARENT_ID

In the TopicTree class (mapping given below), we have three things of interest, the parent (which can be null), the node (basically the Topic itself), and children (all Topics that have parent_id = this topic). The mapping works fine in retrieving the parent and node, but for the children set, it is retrieving the same object as the node itself. I.e. If I fetch a TopicTree item with node: Topic #3, it will also set Topic #3 in the children, instead of the children. I have tried different adjustments to the mappings, like using parent_id, or the TOPIC's topic_id with little luck.

So I am asking if this kind of mapping is possible. We are prepared to move the PARENT_ID into the TOPIC table to make this work, but wanted to ask this to the forums as a last-ditch attempt.

Thanks in advance.


Hibernate version:
2.1.6

Mapping documents:

<hibernate-mapping>
<class
name="com.foo.domain.domain.resource.TopicTree"
table="foo_topic_tree"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="topic_tree_id"
type="long"
>
<generator class="native">
<param name="sequence">foo_topic_tree_id_seq</param>
</generator>
</id>

<many-to-one
name="node"
class="com.foo.domain.domain.resource.BasicTopic"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="topic_id"
/>

<many-to-one
name="parent"
class="com.foo.domain.domain.resource.BasicTopic"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="parent_id"
/>

<set
name="children"
table="foo_topic_tree"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>

<key
column="topic_id"
/>

<one-to-many
class="com.foo.domain.domain.resource.BasicTopic"
/>
</set>

<property
name="displayIndex"
type="int"
update="true"
insert="true"
column="display_index"
/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>

</class>

</hibernate-mapping>


Name and version of the database you are using:
Oracle 9i


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.