-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cascade save map key objects
PostPosted: Fri Apr 01, 2005 4:10 pm 
Beginner
Beginner

Joined: Tue Jun 29, 2004 3:44 pm
Posts: 43
Hello All,

I'm using Hibernate 3. I have a Party class with a Map of Capability objects using CapabilityType objects as keys. I need the map to be persisted when detached Party objects are saved (using merge() ). The mapped values all cascade perfectly (thanks!) and the keys cascade if I map them as a <composite-map-key> like this:

Code:
<map name="capabilities"
   table="PARTY_CAPABILITIES"
   cascade="all,delete-orphan">
                  
   <key column="OWNER_ID"/>

   <composite-map-key class="CapabilityType">
       <!-- This works but stores the CapabilityType information in the PARTY_CAPABILITIES table. -->
      <key-property name="name" column="NAME" type="string" />
      <key-property name="description" column="DESCRIPTION" type="string" />
   </composite-map-key >
         
   <one-to-many class="Capability" />         
</map>


I would really like the key class to be in a separate table, however. Ideally I would use a mapping like this:

Code:
<map-key-many-to-many column="KEY_ID" class="CapabilityType" />
<!-- This stores CapabilityTypes in their own table but does not cascade. -->


But the <map-key-many-to-many> does not cascade saves. I get errors because the key has not already been saved. I'm not going to be able to save the keys separately since the objects are detached when the map is changed.

Is there a way to cascade to a <map-key-many-to-many> ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 4:13 am 
Newbie

Joined: Wed Feb 25, 2004 5:28 pm
Posts: 15
I do not know how to do cascade for a map many-to-many case.

I am trying to do what you have done - map, composite-map-kay and one-to-many. I need some help.

Is Capability a normal persistent class using class element ?

Is this a collection: <one-to-many class="Capability" /> and what is the java implementation for this collection. I tried using HashMap (if HashMap what should be key? ) and ArrayList and get different problems,.

Will be glad to get a reply.
/Kwan


Top
 Profile  
 
 Post subject: It's intended behavior?
PostPosted: Fri Aug 04, 2006 10:34 am 
Newbie

Joined: Wed Aug 02, 2006 4:46 pm
Posts: 2
I've the same problem, and have been digging through the forums for an answer. I've found this post:

http://forum.hibernate.org/viewtopic.ph ... ys+cascade

So apparently this is intentional. It would be very helpful if this behavior were documented.


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