I have an Activity class that maps to table activity.
I have a Profile class that maps to profile table. Everytime the profile is updated I create a ProfileHistory object and save it in profile_history table.
The history should never be modified.
Now in special cases I want to associate the Activity with ProfileHistory in activity_profile_history_xref table which only saves the id of the activity and profile_history:
Here is the related hbm file in Activity :
Now here is the problem:
profileHistory has an attribute Facility. ProfileHistory objects could be pointing to the same Facility object.
Hence when I retrieve multiple profileHistory objects that point to the same Facility object and associate them to Activity and then save the Activity object, I get
a different object with the same identifier value was already associated with the session [for Facility object]
And the problem is that hibernate is trying to update the profileHistory, while nothing has changed on the profileHistory side ( I can tell from the hibernate sql statements).
Is there a way to force hibernate to just update the Activity object?
So far my only solution was to do something like this:
Could someone suggest a better way?
Thanks in advance.
zabet tyan
Ranch Hand
Joined: Jan 14, 2009
Posts: 32
posted
0
I used merge() and everything seems ok now. But the question remains...why does hibernate update something that hasn't changed?!