-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to Map the following relationship?
PostPosted: Wed Sep 14, 2005 6:50 am 
Newbie

Joined: Fri Apr 22, 2005 8:40 am
Posts: 3
Hibernate version: 3.0.5

Name and version of the database you are using:Oracle9i

Hi,

how can I map a bidirectional, one-to-many parent-child relationship, so that the order of the children will be preserved (we use now java.util.List collection for the children, but it can be changed) and a 'delete on cascade' constraint applies?

I use the following mapping now, but the column ROW_NO isn't filled in the database after saving the objects:

Parent (simplified version):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">

        <class name="de.gabo.converter.common.data.rackdesign.DRackDesign"
                table="CON_RD_RACKDESIGN">

            <id name="m_id" column="ID">
                <generator class="sequence">
                    <param name="sequence">SEQ_RD_RACKDESIGN</param>
                </generator>
            </id>

            <component name="m_codeNumber">
                <property name="m_sOrderNumber">
                    <column name="CODENUMBER" length="25" not-null="true"/>
                </property>
            </component>

            <property name="m_projectName">
                <column name="PROJECTNAME" length="64"/>
            </property>

            <property name="m_remark">
                <column name="REMARK" length="4000"/>
            </property>

            <list name="m_wireList" fetch="join" cascade="all-delete-orphan" lazy="true" inverse = "true">
                <key column="RACKDESIGN_ID" on-delete="cascade"/>
                <list-index column="ROW_NO"/>
                <one-to-many class="de.gabo.converter.common.data.rackdesign.DWire"/>
            </list>

        </class>
</hibernate-mapping>


Child (simplified version):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">

        <class name="de.gabo.converter.common.data.rackdesign.DWire"
                table="CON_RD_WIRE">

            <id name="m_ID" column="ID">
                <generator class="sequence">
                    <param name="sequence">SEQ_RD_WIRE</param>
                </generator>
            </id>

            <component name="m_codeNumber">
                <property name="m_sOrderNumber">
                    <column name="ORDERNUMBER" length="25"/>
                </property>
            </component>

            <property name="m_remark">
                <column name="REMARK" length="23"/>
            </property>

            <many-to-one name="m_rackDesign" index="ROW_NO" not-null="true">
                <column name="RACKDESIGN_ID"/>
            </many-to-one>

        </class>
</hibernate-mapping>


thank you,
torel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 7:00 am 
Newbie

Joined: Fri Sep 02, 2005 12:47 pm
Posts: 14
Location: muenchen
Hi,

looke at my post

http://forum.hibernate.org/viewtopic.php?t=947553

plus

http://www.hibernate.org/116.html?cmd=prntdoc

paragraph: Can't I have a bidirectional association using a List or Map?

Sincerely,

Pawel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 8:43 am 
Newbie

Joined: Fri Apr 22, 2005 8:40 am
Posts: 3
Thanks for the help.

I must add inverse="true" to the parent mapping, because I want to declare on-delete="cascade" to improve deletion performance.

Then, according to your references I have to take care of managing the index-column myself.

Will Hibernate manage this case in the future?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 9:29 am 
Newbie

Joined: Fri Sep 02, 2005 12:47 pm
Posts: 14
Location: muenchen
i have currently mapping as following

/parent/

<list name="array"

cascade="all,delete-orphan">
<key column="PARENT_ID"/>
<list-index column="listnumber"/>
<one-to-many class="child"/>
</list>


/child/


<many-to-one
name="parent"
column="PARENT_ID"
class="parent"
not-null="true"
insert="false"
update="false" />

There is no inverse true on parent side but instead there is an insert, update false on child side.

It is working okay but I haven't tested it extensively on cascading behaviore.

I belive it is a bug that hib. do not suport inverse true on lists and hope it is going to be corrected.

Sincerely,

Pawel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.