我们正在开发一个Web应用程序:
我们的EntityManagers都在Spring配置文件中配置,具有下一个相关属性:
<prop key="hibernate.transaction.jta.platform">
org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform
</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<!-- validate | update | create | create-drop -->
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="javax.persistence.transactionType">JTA</prop>
<prop key="javax.persistence.validation.mode">AUTO</prop>
在Spring中声明事务管理器
<tx:jta-transaction-manager />
问题在于,在抛出ConstaintViolationException时,在某些服务调用(只有少数几个)中,它会以某种方式被以下记录的异常链替换:
18:34:54,334 INFO [stdout] (http-localhost/127.0.0.1:8080-6) java.sql.SQLException: javax.resource.ResourceException: IJ000460: Error checking for a transaction
18:34:54,334 INFO [stdout] (http-localhost/127.0.0.1:8080-6) at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:147)
18:34:54,334 INFO [stdout] (http-localhost/127.0.0.1:8080-6) at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
...
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) Caused by: javax.resource.ResourceException: IJ000460: Error checking for a transaction
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:362)
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:139)
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) ... 111 more
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) Caused by: javax.resource.ResourceException: IJ000459: Transaction is not active: tx=TransactionImple < ac, BasicAction: 0:ffff0ac00166:4484bcaf:543e967d:154 status: ActionStatus.ABORT_ONLY >
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:352)
18:34:54,340 INFO [stdout] (http-localhost/127.0.0.1:8080-6) ... 113 more
我能够确定调试应用程序的原始ConstraintViolationException,但我无法在日志中看到它。即使我试图调试和导航第二个异常,它不包含原因ConstraintViolationException,显然是一个不同的。
也许TwoPhaseCoordinator.beforeCompletion在ConstaintViolationException之后抛出第二个异常?如何记录第一个异常,以了解哪些约束已被违反?