-->
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: Using Interceptor for recording of changes history?
PostPosted: Wed Apr 14, 2004 3:24 am 
Newbie

Joined: Tue Apr 13, 2004 6:41 am
Posts: 19
Hi,

I am trying to understand if it would be possible to use iterceptor to track and log history of entity changes.

For Example:

public class HistoryHook implements Interceptor {
private Session cs;
public HistoryHook(Session s) {
cs=s;
}
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException {
if(entity instanceof HistoryEntry) return false;
HistoryEntry h = new HistoryEntry(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types);
cs.save(h);
return false;
}
}

Can I do this?
HistoryEntry will go under same DB commit as entity?

Rihards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
An interceptor can be used for that, the problem is you can't use the same session. There is a trick however: Get the connection from the intercepted session, and pass it to a new session used only in the interceptor. It will use the same transaction then.


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.