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.