-->
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.  [ 1 post ] 
Author Message
 Post subject: Collections - Map
PostPosted: Sat Nov 04, 2006 11:56 pm 
Newbie

Joined: Tue Sep 19, 2006 8:28 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.3

Hi Guys.

Am having some problem with Collections and was hoping someone can give me few ideas how fix the issues.
here is the problem.

I am using Map Collection to do one-to-many association and the map key i am using is the id attribute of a Object.
So i have a child class that has id property which i use as a map key when mapping 1-to-many from parent.

Now, when adding new child objects into the collection since the id of the new child object is null, i put a temp key in the map which is the hashcode() of the object.

Once hibernate saves the date it generates the keys for the child classes and the Map key should now become the Id value of the object instead of the hashcode which i used .



So how can i change the map key values from my temp value to the object id property.


- What i have done is in the parent object implement Flush Aware events and onces this is called this is what i do


public void onFlush() {

//loop through the collection i am interested in and key if the map key is same as the object id.
if Not then remove this object from the map and insert again with the key=object id property.

////doing so will remove all the object from this collection that had the temp keys and will insert it again with the correct key.

}

Is there any other ways ??

- This collection is lazy loaded.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.