views:

82

answers:

1

I created an hibernate interceptor :

public class MyInterceptor extends EmptyInterceptor {

private boolean isCanal=false;

public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[] arg3, Type[] arg4) throws CallbackException {

 for(int i=0;i<100;i++){
  System.out.println("Inside MyInterceptor(onSave) : "+entity.toString());
 }
 if(entity instanceof Canal){
  isCanal=true;
 }
 return false;
}

public void afterTransactionCompletion(Transaction tx){
 if(tx.wasCommitted()&&(isCanal)){
  for(int i=0;i<100;i++){
   System.out.println("Inside MyInterceptor(afterTransactionCompletion) : Canal was saved to DB.");
  }
 }
}

but the method afterTransactionCompletion doesn't get executed after a transaction is commited. I've tried all the ways I know of but I can't make it work. What's more surprising is that the onSave method works fine.

Help !

Could this be due to this bug ? :
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1956

How can I circumvent this bug if it's the cause ?

A: 

What is the signture of afterTransactionCompletion supposed to be? In the documentation I found it says:

void afterTransactionCompletion(boolean successful, Transaction tx)

In which case it's no surprise your method is not called.

I think if you use the @Override annotation you would be warned by the compiler that you've got the signature wrong.

djna
I used this documentation : https://www.hibernate.org/hib_docs/v3/api/org/hibernate/EmptyInterceptor.html#afterTransactionCompletion(org.hibernate.Transaction) .It seems that we're not using the same doc. plz, explain.
Attilah
well I just googled. However the key point is to look at the EmptyInterceptor's signature - does your signature match?
djna
I used the @Override annotation.my signature does match the EmptyInterceptor's signature.
Attilah