-->
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.  [ 5 posts ] 
Author Message
 Post subject: cascade delete question
PostPosted: Mon Apr 05, 2004 11:31 pm 
Newbie

Joined: Fri Apr 02, 2004 4:12 pm
Posts: 12
Given the mapping below, how come a deleting a "parent", SupplierModel, doesn't cascade to deleting the "child", SupplierCarrierModel? It works if I make SupplierCarrierModel a composite-element of SupplierModel, but then other things didn't work. Is there any reason why this isn't working??
Code:
<hibernate-mapping>
    <class
        name="SupplierModel"
        table="PLDT_SUP"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="supplierNumber"
            column="NBR_BSA_SUP"
            type="java.lang.String"
        >
            <generator class="assigned">
            </generator>
        </id>

        <property
            name="supplierName"
            type="java.lang.String"
            update="true"
            insert="true"
            column="NME_BSA"
        />
        <set
            name="supplierCarriers"
            table="PAMT_SUP_CAR"
            lazy="true"
            inverse="true"
            cascade="delete"
            sort="unsorted"
        >

              <key
                  column="NBR_BSA_SUP"
              />

              <one-to-many
                  class="SupplierCarrierModel"
              />
        </set>
    </class>
    <class
        name="SupplierCarrierModel"
        table="PAMT_SUP_CAR"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <composite-id
            name="id"
            class="SupplierCarrierModelKey"
        >
                    <key-many-to-one
                        name="supplier"
                        class="SupplierModel"
                        column="NBR_BSA_SUP"
                    />
                    <key-many-to-one
                        name="carrier"
                        class="CarrierModel"
                        column="NBR_CAR"
                    />
                    <key-many-to-one
                        name="product"
                        class="ProductModel"
                        column="CDE_PRD_GRD"
                    />
        </composite-id>
        <!-- more properties... -->
    </class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 12:41 am 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
where is the code that actually deletes the children?

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 9:19 am 
Newbie

Joined: Fri Apr 02, 2004 4:12 pm
Posts: 12
micho2001 wrote:
where is the code that actually deletes the children?

I was wondering more about deleting the parent. Why does that not "cascade" to automatically deleting the children? Or am I misunderstanding cascading. If I put the children as a composite-element, they are deleted when the parent is deleted. Why no this way?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 10:27 am 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
You are using inverse=true , that means it is the children who manage the link.

You could try all-delete-orphan and use child.setParent(null);

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 10:38 am 
Newbie

Joined: Fri Apr 02, 2004 4:12 pm
Posts: 12
So, in other words, I will need to "manually" delete the children? That's not a problem.

From a "design" stand-point, am I otherwise using this relationship properly/normally?


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