Spring 事务注释和持久上下文上的只读标志
阅读有关 Spring 事务注释上的 readOnly 标志的信息,它从 javadoc 中说“这只是作为实际事务子系统的提示;它不一定会导致写入访问尝试失败。无法解释读取的事务管理器-only 提示在请求只读事务时不会引发异常”。
- 但据说用只读标记,从数据库检索的实体不会存储在持久上下文中,或者以其他方式表示第一级缓存被禁用,因为实体不会存储在持久上下文中。这是对的吗?
- 如果这是正确的,为什么如果我调用entityManager.contains()它总是返回true,尽管我将事务标记为readOnly true?
- 如果实体确实存储在持久上下文中,我如何才能真正使用 JPA 进行测试?
谢谢
Reading about the readOnly flag on Spring transactional annotation, it says from the javadoc "This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction".
- But its said that marking with readOnly, the entities retrieved from database wont be stored in the persistent context or other way to say it is that the firt level cache is disabled because entities wont be stored in the persistent context. Is this right?
- If this is right, why if I call entityManager.contains() it always returns true although I marked the transactional with readOnly true?
- How can I test really with JPA if the entities are really stored in the persistent context?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论