Calling flush() in @Transactional method in Spring Boot application
是否有可能在@Transactional方法中间调用Hibernate flush()将不完整的结果保存在数据库中?
例如,此功能是否可能将" John"保存到数据库?
1 2 3 4 5 6 7 8 | @Transactional public void tt() { Student s = new Student("John"); em.persist(s); em.flush(); // Perform some calculations that change some attributes of the instance s.setName("Jeff"); } |
我在H2内存数据库中进行了尝试,但没有保存不完整的事务更改。 但是在某些情况下,也许在另一个数据库引擎上,这可能吗?
在调用
This operation will cause DML statements (insert/update/delete etc) to be executed to the database but the current transaction will not be committed. That means flush() will not make current changes visible to other EntityManager instances or other external database clients; that will only happen at the transaction commit. In other words flush() operation will only flush the current memory cache from EntityManager to the database session.
因此,刷新可能会引发一些JPA异常,但实际上不会在事务结束之前将其提交给数据库。
相关问题:JPA刷新与提交