我已经完成了一个拦截器(基于EmptyInterceptor创建自己的拦截器)。我能够在onFlushDirty()中获得所有更改(合并,保存,saveOrUpdate和删除)。
我使用的EmptyInterceptor方法:
@Overridepublic boolean onFlushDirty(Object object, Serializable id, Object[] newValues, Object[] oldValues, String[] properties, Type[] types) throws CallbackException {@Overridepublic boolean onSave(Object object, Serializable id, Object[] newValues, String[] properties, Type[] types) throws CallbackException {@Overridepublic 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());



