-->
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.  [ 4 posts ] 
Author Message
 Post subject: pojo old values before update
PostPosted: Fri May 06, 2005 3:25 am 
Newbie

Joined: Thu Dec 16, 2004 12:56 pm
Posts: 9
Hi,
is possible to get the original value (old value) of the pojo before the update?
I saw that with the "dynamic update" flag Hibernate determines automaticaly which field is changed. Can I call this api programmatically?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 2:54 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
You could open a new (different) session and perform a session.get( ) or session.load( ) on the object using the class and primary key value to load the current persisted state of the object. You could also set the flush mode of the current session to FlushMode.COMMIT or FlushMode.NONE to allow dirty reads before performing the session.get( ) or session.load( ).
You can then do a comparison once you have loaded the old state.

I don't think that you can call the dynamic update API through the interfaces...you would have to cast the session to a SessionImpl, and even then the fields might be private. Take a look at the source code...

I wouldn't try any of these approaches unless you have a *very* compelling reason to look at the old state, and if that were the case, a Memento pattern implementation for your POJOs might be a better solution. Keep in mind that Hibernate manages a lot of stuff, and anything you try to manage in your code will possibly be in conflict with Hibernate and may have unpredictable (or at least undefined) results.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 3:07 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
Take a look at the interceptor. There is a method on there, onFlushDirty() that contains the previous state. Not sure if this will help or not.

_________________
Matt Veitas


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 9:55 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
Well, then, that's much easier. I suppose I should actually look at the API before I open my mouth :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.