This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prevent update on cross-refrence table Hibernate

 
zabet tyan
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have the following problem:

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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used merge() and everything seems ok now. But the question remains...why does hibernate update something that hasn't changed?!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic