我遇到了一个情况:
save
或update
hibernate 的目标表中的某些数据insert
或update
操作之前执行但是我发现触发器未修改的字段并没有真正被取出。
这与Hibernate的事务提交(已经调用了flush())或Hibernate缓存有关吗?谢谢。
最佳答案
这可能是由于第一次( session )缓存或第二次(例如ehcache)缓存引起的。要重新读取实体,您需要调用session.refresh()。
从hibernate docs(在本节底部)
It is possible to re-load an object and all its collections at any time, using the refresh() method. This is useful when database triggers are used to initialize some of the properties of the object.
sess.save(cat);
sess.flush(); //force the SQL INSERT
sess.refresh(cat); //re-read the state (after the trigger executes)
关于hibernate - 数据库触发器和 hibernate ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6980875/