私はこれをインターセプターで行いました(EmptyInterceptorに基づいて独自に作成しました)。onFlushDirty()ですべての変更(マージ、保存、saveOrUpdate、削除)を取得できました。
私が使用したEmptyInterceptorのメソッド:
@Override
public boolean onFlushDirty(Object object, Serializable id,
Object[] newValues, Object[] oldValues, String[] properties,
Type[] types) throws CallbackException {
@Override
public boolean onSave(Object object, Serializable id, Object[] newValues,
String[] properties, Type[] types) throws CallbackException {
@Override
public void onDelete(Object object, Serializable id, Object[] newValues,
String[] properties, Type[] types) throws CallbackException {
onFlushDirty()で、エンティティの以前の状態を照会する必要がありました。
Connection c = sessionFactory.getCurrentSession().connection();
Session session = sessionFactory.openSession(c);
BaseEntity newBaseEntity = (BaseEntity) object;
BaseEntity oldBaseEntity = (BaseEntity) session.get(newBaseEntity.getClass(), newBaseEntity.getId());