-->
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: Recursive RElationship in Hibernate
PostPosted: Wed May 25, 2005 6:40 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp


Hello all,
i have a table that contains 'Containers'. IN the same table i have both parent and children,
e.g. a bag is in a box which is in a room which is in a building

all bag, box,room and building are in the same table, and i wanted to know if Hibernate is able to handle relationships on the same table..

anyone can clarify?

thanx and regards
marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 7:15 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
I have this Module object which has parent Module and children Modules.
And it works OK for me.

Code:
<hibernate-mapping>

    <class
        name="com.foo.common.web.module.Module"
        table="modul"
        lazy="false"
        dynamic-update="false"
        dynamic-insert="false"
        mutable="false"
    >
        <cache usage="read-only" />

        <id
            name="id"
            column="modul_id"
            type="int"
            unsaved-value="0"
        >
            <generator class="native">
            </generator>
        </id>

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

        <property
            name="status"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="status"
        />

        <many-to-one
            name="parent"
            class="com.foo.common.web.module.Module"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="parent_id"
        />

        <set
            name="children"
            table="modul"
            lazy="false"
            inverse="true"
            cascade="all"
            sort="unsorted"
            order-by="orderby"
            where="status > 0"
        >
            <cache
                usage="read-write"
             />

              <key
                  column="parent_id"
              >
              </key>

              <one-to-many
                  class="com.foo.common.web.module.Module"
              />
        </set>

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

        <property
            name="order"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="orderby"
        />

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

        <property
            name="showHelp"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="showHelp"
        />

        <set
            name="users"
            table="moduleuser"
            lazy="true"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >
              <key
                  column="modul_id"
              >
              </key>

              <many-to-many
                  class="com.foo.ecos.data.User"
                  column="euser_id"
                  outer-join="auto"
               />

        </set>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Module.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


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.