我们什么时候对 setComplete() 使用 hibernate 的会话刷新
我在使用单元测试用例时阅读了有关 Hibernate setComplete() 方法的 spring 文档。我对 setComplete() 与 session 的lush() 方法感到困惑。两者都负责通过从内存加载到实际数据库来使对象的状态在数据库中持久化。如果有人可以帮助我获得与此相关的良好资源/示例,那就太好了。我将非常感激。
谢谢, 毛利克
I've read spring documentation regarding Hibernate's setComplete() method while working with Unit Test Cases. I am confused between setComplete() versus session's flush() method. Both are responsible to make object's state persistent in Database by loading from memory to actual Database. It will be great if somebody can help me to get good resources/examples regarding the same. I will highly appreciate it.
Thanks,
Maulik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,
setComplete()
不是 Hibernate API 的一部分(请在引用某些内容时提供链接),它是AbstractTransactionalSpringContextTests
这是一个基于 JUnit 3.8 的测试的便捷基类,应该在事务中进行,但通常会在每次测试完成时回滚事务。setComplete( )
方法允许更改此默认事务行为。来自其 Javadoc:文档的以下部分提供了更具体的用例:
Hibernate 的 Session#flush() 非常不同,它只是告诉 Hibernate 将挂起的更改写入数据库,它不与事务交互。
To my knowledge,
setComplete()
is not part of Hibernate's API (please provide a link when you are referring to something), it is part of the API ofAbstractTransactionalSpringContextTests
which is a convenient base class for JUnit 3.8 based tests that should occur in a transaction, but normally will roll the transaction back on the completion of each test. ThesetComplete()
method allows to alter this default transactional behavior. From its Javadoc:The following section of the documentation gives more concrete use cases:
Hibernate's
Session#flush()
is very different, it just tells Hibernate to write pending changes to the database, it doesn't interact with the transaction.