-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Catch dirty sub-objects and persist as them new objects
PostPosted: Thu Jun 02, 2005 6:27 am 
Newbie

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.