You can have something like this:
Code:
public class MyInterceptor extends EmptyInterceptor {
public boolean onSave(Object entity, Serializable id, Object[] state,
String[] propertyNames, Type[] types) throws CallbackException {
if(entity instanceof Withdrawal) {
Withdrawal itm = (Withdrawal) entity;
if(itm.getAmount() > 500000) {
throw new CallbackException("Withdrawal limit exceeded");
}
}
return false;
}
}
Now while opening a session you can use this interceptor like:
Code:
Session session = HibernateUtil.getSessionFactory().openSession(new MyInterceptor());
session.beginTransaction();
.............
.............