-->
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.  [ 3 posts ] 
Author Message
 Post subject: getOriginal, getEntity and getResult in MergeEvent
PostPosted: Wed Dec 26, 2007 9:03 am 
Newbie

Joined: Thu Nov 22, 2007 6:11 am
Posts: 6
Hello
I am playing with the EventListener and in fact I was searching for a way to get the Old values and the new values of an object when I try to reattach it (an update or merge call).
It is like with update I can't get this information but with merge if my entity is already loaded in the Session, I expected to get these old and new values.
I was wondering what the different Object returned by getOriginal, getEntity and getResult represent in the mergeEvent. Because if I add a mergeListener after the default merge, all the objects are identical.

I also looked at "lower level" listeners but I can't use them as I would like to be able to still interact on the session entities.


Thanks for your help

Pascal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 11:13 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Hi,

maybe it is not the EventListener you are looking for but an Interceptor. I suppose you want to get something like a history of your entities.

Maybe you try something like this:

public class HistoryInterceptor extends EmptyInterceptor {

private static Logger logger = LoggerFactory.getLogger(HistoryInterceptor.class);

/**
* Called when an object is detected to be dirty, during a flush. The interceptor may modify the detected
* <tt>currentState</tt>, which will be propagated to both the database and the persistent object.
* Note that not all flushes end in actual synchronization with the database, in which case the
* new <tt>currentState</tt> will be propagated to the object, but not necessarily (immediately) to
* the database. It is strongly recommended that the interceptor <b>not</b> modify the <tt>previousState</tt>.
*
* @return <tt>true</tt> if the user modified the <tt>currentState</tt> in any way.
*/
@Override
public boolean onFlushDirty(final Object pEntity,
final Serializable pId,
final Object[] pCurrentState,
final Object[] pPreviousState,
final String[] pPropertyNames,
final Type[] pTypes) throws CallbackException {
...
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 2:11 pm 
Newbie

Joined: Thu Nov 22, 2007 6:11 am
Posts: 6
You re right but I wanted to avoid Interceptor.
I found also something like the FlushEntityListener that is interesting but all that stuff is not convenient for me as I cannot at that level perform any update of Objects of the session :( unless I do some specific SQL querying.

Thanks for your advice


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