What's flushed by Hibernate's Session.flush()
当我在打开的hibernate会话中调用Session.flush()时,会发生什么情况?是将我使用保存/更新/删除更改(持久化,删除,更新)的所有实体都写入数据库,还是将会话中的所有实体都写入数据库(如果我没有对其进行调用等)?
我发现有很多有关此问题的Hibernate资源,但是没有什么能确切地找到我想要的答案。
一个简单的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | class A { @OneToOne public B b; public int x; } class B { @OneToOne(mappedBy="b") public B b; public int y; } // Example A a = aDao.load(...); a.x = 20; b.y = 15; aDao.update(a); // Question: Will this update b's value to 15 in the database? session.flush(); |
如果在上面的示例中将更新B,我该如何防止它?
感谢您的帮助!
所有更改都将写入数据库。您未创建/修改/删除的对象不会被保存。
我不确定