gpt4 book ai didi

java - Play 2.5 - @Transactional readOnly 被忽略?

转载 作者:行者123 更新时间:2023-12-01 19:41:53 24 4
gpt4 key购买 nike

我有一个 Java Play 2.5 应用程序,并且有一个标记为只读的事务(在 Controller 级别):

    @Transactional(readOnly = true)
public Result list() { ...

(这是 play.db.jpa.Transactional 注释)。

因此,如果我打开 hibernate 事务日志记录:

 <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")),并在事务结束时将其保存到数据库中!

我期待一个异常告诉我该事务是只读的并且无法提交!

  1. 为什么事务不是只读的?
  2. 我能否以某种方式在日志中查看 Hibernate 是否以只读方式创建事务?

其他信息:Java Play 2.5.10、Hibernate 5 (5.2.6) 和 PostgreSQL 作为数据库。

最佳答案

所以,看来是因为 Controller 类本身带有@Transactional注解,并且方法带有@Transactional(readOnly=true)。

不知何故,类注释会覆盖方法注释。这对我来说似乎不合逻辑,但实际上,情况似乎如此:一旦我从类级别删除了 @Transactional,它就工作得很好。

关于java - Play 2.5 - @Transactional readOnly 被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59166321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com