-->
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: strange update behavior
PostPosted: Fri Jun 11, 2004 2:43 pm 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
ok, i save Parent object, which a list of Child objects.

now, when i get Parent object from the store, and update the collection (add and delete from children), then save it, all is fine (using all-delete-orphans)

but, when i get create a new Parent object (coming down from the web layer, populated from a form, but with the same id), that has a new list of children, when i save it the old children do not go away in the database.

if i getChildren() from the old parent, and use it to setChildren() on the new parent, is still leaves the old children in the db (altough it nulls out the FK fields)

i don't understand this behavior. YES I"VE READ THE MANUAL, many times.

basically when i update an existing parent object, i want to blast all the existing children, and add the new ones.

anyone know why this isn't working? seems like a pretty standard thing to do.

thanks.
G


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 11, 2004 8:04 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Are you using saveOrUpdateCopy, when you save the Parent object? Mapping files and your Java code for doing the update would be useful.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 12:19 pm 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
no, i wasn't using saveOrUpdateCopy, just saveOrUpdate, although i tried that and got the same result.

other people must be having this same problem, in the web world, where the client is an HTML page, and you are forced to create a new instance of an object and populate it. in my object, i want to just blast all the existing children and add new ones, then save the parent. but hibernate doesn't like this, and it leaves turds around in the database (it blanks out the old childrens' id's, instead of removing them. please help this is killing me!

<class name="apacs.profile.Profile" table="Profile">
<id name="id">
<generator class="uuid.hex"/>
</id>
<property name="email"/>
<property name="address"/>
<property name="faxNumber"/>
<property name="firstName"/>
<property name="lastName"/>

<list name="permissions" lazy="false" cascade="all">
<key column="parentid"/>
<index column="listindex" type="string"/>
<one-to-many class="apacs.profile.ProfilePermission"/>
</list>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 12:41 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Ok, you need to use saveOrUpdateCopy which will allow you to save an object rebuilt from the web-layer.

The problem with it not deleting children is that (I'm assuming), the parent-child relationship is unidirectional (child has no knowledge of the parent). If this is the case, your mapping should look like the following:

Code:
<class name="apacs.profile.Profile" table="Profile">
    <id name="id">
        <generator class="uuid.hex"/>
    </id>
    <property name="email"/>
    <property name="address"/>
    <property name="faxNumber"/>
    <property name="firstName"/>
    <property name="lastName"/>

    <list name="permissions" lazy="false" cascade="all-delete-orphan">
        <key column="parentid"/>
        <index column="listindex" type="string"/>
        <one-to-many class="apacs.profile.ProfilePermission"/>
    </list>
</class>


The cascade must be set to all-delete-orphan if you wish the children to be "blasted". I've got a test-case with your scenario in, and this works fine.[/code]


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.