为什么我的 Jboss 服务器开始处理所有内容?

Why does my Jboss server begin transactions for everything and anything?

我正在为

的问题而苦恼

我没有得到答案,但 BalusC 表示怀疑我的... "JSF managed bean is transactional..? This is not the default behavior. What annotations do you all have on your JSF backing bean class? You should basically separate transactional methods into a true service class and then in turn inject that in your JSF managed bean."

我喜欢这个想法,但问题是我的任何 bean 上都没有任何与事务相关的注释。我为 com.arjuna.ats.jta 打开跟踪日志记录,发现容器打开和关闭事务。到目前为止,如预期。

但它对所有内容都这样做。 从服务器请求静态 PNG?开始交易。 运行 通过 @Schedule 的方法?开始交易。不涉及实体管理器、数据库或任何事务。

这是预期的行为吗?

我什至在没有数据库的服务器上部署了一个新的测试项目,即使在那里,Arjuna 也会为每次调用开始交易。

当我创建的任何和所有 bean 都已经附加了活动事务时,我应该如何将我的数据库方法分离到一个真正的服务 bean 中?

Is this the expected behavior?

嗯,不。至少就 Java EE、JSF 和 EJB 而言不是。就是这样。

但是该项目(以及我用来尝试对问题进行三角剖分的新测试项目的足够多的 pom 文件)是 EE6 和 Seam 3 的混蛋。而且 Seam 3 comes with a built-in, automatic transaction wrapper:

Seam Transaction has a built in ServletRequestListener which automatically begins and commits (or rolls back if the transaction is set to rollback) a transaction for each request! This should end having to manually specify transactions, or wonder if a transaction is inplace.

Tip

Should the need arise for disabling this listener, a context param in web.xml named org.jboss.seam.transaction.disableListener set to true will disable the listener.

因此,在我看来,为了将我的数据库调用重构为真正的服务 bean,我有三个选择:

  • 禁用侦听器
  • 从 pom 中完全删除 Seam Transactions (org.jboss.seam.transaction)
  • 升级到 EE7 /JSF 2.2 并摆脱 Seam

编辑:

但这还不是全部。 @Schedule 方法在 class 中,用 @Singleton 注释,使其成为一个 EJB,那些 默认是事务性的。用 @TransactionAttribute{SUPPORTS} 注释那个特定的 class (即“如果有一个事务就使用一个事务,如果没有就不要打开一个新事务”)解决了这个问题。