在onBeforeCommitChanges事件里能获得实体的原始值吗?就是界面刚打开的时候的值(用户修改前)
是否可以在 init 方法里面用一个类变量暂存一下?
如果系统没提供方法,那只能这样干了
我见过一种在实体EntityListener的用法:
- 实体里定义一个@Transient属性,叫prevXxx的。
- 在onBeforeDetach中,将prevXxx设置为当前值。
@Override
public void onBeforeDetach(Client entity, EntityManager entityManager) {
if (!persistence.getTools().isDirty(entity)) {
entity.setPrevXxx(entity.getXxx());
}
}
- 在onAfterUpdate中取出来做需要的判定;判定完后更新prevXxx到新的值。
- 在onAfterInsert中也设置一下prevXxx。
感觉你按照上面的方法设置了preXxx,在onBeforeCommitChanges里能取到。
2 个赞
感谢感谢!