Joined: Thu Jun 02, 2005 5:45 am Posts: 2 Location: Shanghai, China
|
There are oodles of people with this simple scenario:
Take an object out of the database and pass it to a client.
The client edits some of the object's children and then passes the whole thing back to the server for saving.
Hibernate makes this operation easy.
In my case though I don't want changed sub-objects to be updated in place (i.e. the objects in the database should be immutable).
Instead I want to persist changed sub-objects as brand new objects.
I can't for the life of me figure out how to make this work.
I tried making an Interceptor and doing the work in the onFlushDirty method.
---Steps:
-Create new session
-Nullify entity ID and save
-copy old state into new state
-allow original update to finish
---Problems:
-ugly hack
-sub-sub-objects might be incorrectly associated with the original object?
I tried overriding the onPreUpdate event in a similar way (its easier to get a session this way) but i can't figure out how to cancel the original update.
I finally broke down and wrote some horrendously awful object diffing code to nullify the ID of any changed objects before doing a saveAndUpdate.
I don't mind hitting the database to find changed objects I just want a simple consistent algorithm.
Ideas would be greatly appreciated as I'm out of them. I'm using Hibernate 3.
Thanks in advance,
Jacob
|
|