-->
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.  [ 2 posts ] 
Author Message
 Post subject: Best way to undo an object save?
PostPosted: Wed Oct 24, 2007 11:59 am 
Newbie

Joined: Fri Jul 28, 2006 10:53 am
Posts: 15
I need to support undo operations in my app, and am in the situation where I have a big tree of Hibernate objects that have been saved/flushed but need to be reverted to their state right before the save/flush (using long-running sessions).

I've been doing:
Code:
session.save(object);
session.flush();

...

session.delete(object);
object.setId(null);
session.flush();

...

session.save(object);
session.flush();

which works, except when sets are involved. In that case, I have to get very dirty and do the following for the undo logic:
Code:
...

List<ChildObject> children = new ArrayList<ChildObject)();
for(ChildObject child: object.getChildren())
   children.add(child);

object.setChildren(new HashSet<ChildObject>(0));
session.delete(object);
object.setId(null);
session.flush();

for(ChildObject child: children)
   object.getChildren().add(child);
...


Obviously it's a huge pain to do, especially when a lot of objects are involved. Is there a better solution?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 1:16 am 
Newbie

Joined: Tue Jul 22, 2008 5:10 am
Posts: 3
I second this question...


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

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.