I created an hibernate interceptor :
public class MyInterceptor extends EmptyInterceptor {
private boolean isCanal=false;
public boolean onSave(Object entity, Serializable arg1, Object开发者_如何学Python[] 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 ?
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.
精彩评论