Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update bidirectional relation without updating the objects

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

I have the following problem:

I have two tables

profile and profile history.

These tables have their own back reference tables to an area. (so a profile can have many areas and the history has to keep track of that)

for profile- area:
aac_profile_area_xref: profile_id(FK) and area_id(FK)

for profile_history_area:
aac_profile_his_area_xref: profile_history_id(FK) and area_id(FK).


the area has a version column so hibernate keeps track of every update:

Here is the related part of the hbm files:

for profile:



for profile history:


Now here is the sequence of events that are happening during a profile save (assuming an area is already persisted):

create a profile object.
create a profile history object.
save the history (which updates the area!)
save the profile (which tries to update the area but I get StaleObjectStateException !)

(profile and history are saved in two separate transactions)

Now what I want is a way to force hibernate to not update the area when it is saving it. i.e. just put the area_id and profile_id in the back reference table of the history.

Is there anyway to do this?


Thanks.







 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic