-->
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: Cascade of list with all-delete-orphan : child not deleted
PostPosted: Fri Mar 30, 2007 4:59 am 
Newbie

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

Hibernate version: 3.1.3

Mapping documents:
Code:
<hibernate-mapping>
    <class name="CustomerAddress"
           schema="CUSTOMER"
           table="CUSTOMER_ADDRESS"
           optimistic-lock="version"
           lazy="false">

        <id name="oid" length="32">
            <generator class="uuid.hex"/>
        </id>

        <version name="oversion"/>

        <list
                name="customerAddressKinds"
                lazy="false"
                cascade="all-delete-orphan">
            <key>
                <column
                        name="custo_addki_custo_addre"
                        index="ind_custo_addki_custo_addre"/>
            </key>
            <list-index
                    column="custo_addki_custo_addre_index"/>
            <one-to-many
                    class="CustomerAddressKind"/>
        </list>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
public Entity update(Entity entity) {
        ...
            Session session = null;
            try {
                session = currentSession();
                session.update(entity);
            } finally {
                safeCloseSession(session);
            }
            result = entity;
        ...
        return result;
    }

Name and version of the database you are using: Oracle 10


When I update my collection of "customerAddressKinds" after I have removed some customerAddressKind, the child record isn't deleted in the database. Only the foreign key is set to NULL. No other Objects reference the CustomerAddressKind.

I also tried to use the saveOrUpdate method, but is has the same output.
Does someone known why the cascade="all-delete-orphan" is not working like I expect? It should also delete the orphan record.

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 5:44 am 
Beginner
Beginner

Joined: Thu Apr 19, 2007 5:37 am
Posts: 28
You might want to turn on Log4J or Log4Net to see what Hibernate is doing.

On the other hand, I have some similar issue: I don't understand why Hibernates sets my "index" column to "null" with an UPDATE command, and then uses a DELETE command to actually do the deletion.

That's expensive, and I get a "constrain error" because obviously, I don't want my index column to be "null".

Any idea anyone??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 5:56 am 
Newbie

Joined: Thu Apr 08, 2004 4:28 am
Posts: 16
If I understand the Hibernate documentation, child records will not be deleted (only the foreign key will be set to null) when you remove them from the collection and perform an update on the parent object.
Only when you perform a delete on the parent object, also all childs will be deleted.

It should be useful that Hibernate also deletes the child record when it is removed from the collection.

We have the same situation as you have. Hibernate does first an insert without foreign key value. After that it does an update action with the foreign key value. So it the database it is necessary that you define the foreign key column as NULL, so that the first action will not fail.
The same happens in the case of a delete.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 6:15 am 
Beginner
Beginner

Joined: Thu Apr 19, 2007 5:37 am
Posts: 28
Sorry, but I will have to disagree with both of your statements:

1- the children are deleted if you set the "all-delete-orphans" which works just fine, except that it uses an update before deleting (I don't delete the parent, I just clear the collection and add new items to it).

2- the insertions don't insert null, they are done with a single statement and contain the parent_id (at least in my case).


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.