-->
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: Persisting multiple new child Objects stored in a Map
PostPosted: Wed Jul 20, 2005 12:28 pm 
Newbie

Joined: Wed Jul 20, 2005 11:55 am
Posts: 3
I am storing my associations as Maps. I only saveOrUpdate on the parent Object. I cascade updates. When I want to create a new child Object, I simply put it in the map of the parent Object. The id for the new child Object is set using a database sequence, so I never explicitly set the id of the child Object.

When I try to create a single new child Object, it works fine. When I try and add multiple new child Objects it doesn't work at all.

I am assuming the problem has something to do with all of the child Objects having the same, null, id which is used as the key in the Map.

Could anyone shed some light on this situation? How do I persist multiple new child Objects by adding these new child Objects to the Map of the parent Object and calling saveOrUpdate on the parent?

_________________
-tom


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 2:48 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Hi

Code:
cascade="save-update"
in the map tag should do the job.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 2:52 pm 
Newbie

Joined: Wed Jul 20, 2005 11:55 am
Posts: 3
Hello, thank you for responding.

I already cascade="all-delete-orphan", so that isn't the problem. When I only add a single new Object (no id) to the Map and saveOrUpdate the parent Object, the new child object that I stored in the Map persists to the database fine and is assigned a new id off the database sequence. The problem happens when I try to add more than one new child Object to the map and persist the parent Object. When I do this, none of the new child Objects persist back to the database.

Any other ideas?

_________________
-tom


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 31, 2005 5:09 am 
Newbie

Joined: Tue Apr 12, 2005 10:37 am
Posts: 6
Tom,

>> I am assuming the problem has something to do with all of the child Objects having the same, null, id which is used as the key in the Map.<<

I had a similar problem but with sets, where my equals() and hashcode() were based on a database-generated key. This breaks the set contract, causing all sorts of pain (none of it Hibernate's fault).

Solution was to set a generated (private) GUID in the constructor, and base equals() and hashcode() on this, making my sets stable and allowing all my business properties to be mutable. I still use a sequence for the database ID.

John


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.