-->
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: 1:m parent:child relationship with self
PostPosted: Tue Oct 17, 2006 2:31 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
Reading through the hibernate material a parent:child 1:m relationship is typically mapped wtih a Parent domain class and a Child domain class (no problem). What I want to do is map a single domain object to iteself in a parent:child relationship.

For example a fourm that may have a root 'content' item which may have associated child content replies. I want the 'content' domain object to be aware of the child domain objects which are the same type as the parent.

Thoughts?

Thanks in advance for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 3:07 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
Figured it out .. here is some code ...

Code:
    <many-to-one name="parentContent"
      cascade="none"
      outer-join="false"
      foreign-key="FK1_PARENT_CONTENT_ID">
    <column name="parent_content_id"
      not-null="false"
      unique-key="UNIQUE_NAME_AT_LEVEL"/>
    </many-to-one>
    
   <set name="childContents" cascade="all-delete-orphan" lazy="false" inverse="true">
      <key column="parent_content_id"/>
      <one-to-many class="com.tricision.maas.domain.Content"/>
    </set>


this generates the data structure ... (MySQL database)
Quote:
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| content_id | bigint(20) | NO | PRI | NULL | auto_increment |
| content_type_id | bigint(20) | YES | | NULL | |
| content_title | varchar(255) | YES | | NULL | |
| content_text | varchar(255) | YES | | NULL | |
| is_active | bit(1) | YES | | NULL | |
| create_dt | datetime | YES | | NULL | |
| create_user | varchar(255) | YES | | NULL | |
| update_dt | datetime | YES | | NULL | |
| update_user | varchar(255) | YES | | NULL | |
| project_id | bigint(20) | NO | MUL | NULL | |
| parent_content_id | bigint(20) | YES | UNI | NULL | |
+-------------------+--------------+------+-----+---------+----------------+


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.