我有一个Java Play 2.5应用程序,并且有一个标记为只读的事务(在控制器级别):
```js
@Transactional(readOnly = true) public Result list() { ...
(这是play.db.jpa.Transactional批注)。
因此,如果我为休眠事务打开日志记录:
```js
<logger name="org.hibernate.engine.transaction" level="TRACE"/>
然后,我看到事务正在完成并被提交。
019-12-03 23:42:23,754 [debug] from org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator in main - No JtaPlatform was specified, checking resolver
2019-12-03 23:42:23,755 [debug] from org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator in main - No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver]
2019-12-03 23:42:23,766 [debug] from org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver in main - Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-12-03 23:58:46,769 [debug] from org.hibernate.engine.transaction.internal.TransactionImpl in application-akka.actor.default-dispatcher-5 - begin
2019-12-03 23:58:46,878 [error] from application in application-akka.actor.default-dispatcher-5 - Transaction: org.hibernate.engine.transaction.internal.TransactionImpl@3d505ddd[transactionCoordinator=org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl@89a1241,exceptionConverter=org.hibernate.internal.ExceptionConverterImpl@76f0443c,transactionDriverControl=org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl@49f1518a]
2019-12-03 23:59:27,638 [debug] from org.hibernate.engine.transaction.internal.TransactionImpl in application-akka.actor.default-dispatcher-5 - committing
但是,我有一个问题-它不是只读的!我添加了一些修改对象的代码(obj.setField(“ changed value”)),并在事务结束时将其保存到数据库中!
我期待有一个异常告诉我该事务是只读的,并且无法提交!
为什么交易不是只读的? 我能否以某种方式在日志中看到Hibernate是否以只读方式创建事务? 其他信息:Java Play 2.5.10,Hibernate 5(5.2.6)和PostgreSQL作为数据库。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。