afterTrasnactionCommit中的删除操作引发异常

时间:2019-03-22 16:32:07

标签: spring hibernate spring-transactions

我在afterTransactionCommit的上下文中运行。我有一个方法,它被标记为@Transactional(propagation = REQUIRED)。该方法使用JPA EntityManager执行删除操作,该操作委派给在Spring 4.3容器中运行的Hibernate 5。 afterTransactionCommit中正在执行10个操作。每次删除均成功完成,但第十次删除始终失败。使用Hibernate 3.6.x可以成功完成此操作,但是由于我已升级到Hibernate 5.4.x,因此该操作不再成功完成。

启用DEBUG日志记录后,我可以看到该事务仍然处于活动状态,并且TransactionManager找到了JPA事务的EntityManager。发现该事务处于活动状态,并且该操作将参与现有事务。但是当遇到第十次删除操作时,TransactionManger会显示这是参与现有事务的失败,然后将该事务标记为回滚。

我无法确定导致故障的原因。

以前有人遇到过这样的事情吗?

下面的日志文件。

  

2019-03-22 09:00:32,692 [主sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:32,692 [主要sessionId:vaultId:userId:origReqUri:]调试common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:32,725 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:32,725 [主要sessionId:vaultId:userId:origReqUri:]调试common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:32,735 [主sessionId:vaultId:userId:origReqUri:]调试common.infrastructure.TransactionManager的调试-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:32,736 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:32,736 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:32,736 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:32,738 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:32,738 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:32,738 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:32,738 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,266 [main sessionId:vaultId:userId:origReqUri:] DEBUG org.hibernate.SQL-/ *从DObjReference中删除o.instanceId =:instanceId AND o.referencingencingObjectType =:referencingObjectType AND o。 ReferencingObjectKey =:referencingObjectKey和o.referencingParentKey =:referencingParentKey /从d_obj_reference中删除,其中instance_id =?和referenceencing_object_type =?和referenceencing_object_key =?和referencing_parent_key =?   2019-03-22 09:00:33,278 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,278 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,283 [main sessionId:vaultId:userId:origReqUri:] DEBUG org.hibernate.SQL-/ 从属性AS中选择​​AttributeKey o在哪里o.instanceId =:instanceId /从属性attrib0_中选择attrib0_.attribute_key作为col_0_0_,其中attrib0_.instance_id =?   2019-03-22 09:00:33,295 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,295 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,323 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,323 [主要sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,332 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,332 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,332 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,332 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,334 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,334 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:33,334 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:33,334 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:34,133 [main sessionId:vaultId:userId:origReqUri:] DEBUG org.hibernate.SQL-/ 从DObjReference中删除o.instanceId =:instanceId和o.referencingencingObjectType = :referencingObjectType和o。 ReferencingObjectKey =:referencingObjectKey和o.referencingParentKey =:referencingParentKey /从d_obj_reference中删除,其中instance_id =?和referenceencing_object_type =?和referenceencing_object_key =?和referencing_parent_key =?   2019-03-22 09:00:34,145 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:34,145 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:34,150 [main sessionId:vaultId:userId:origReqUri:] DEBUG org.hibernate.SQL-/ 从属性AS中选择​​attributeKey o.instanceId =:instanceId * /选择attrib0_ .attribute_key作为来自属性attrib0_的col_0_0_,其中attrib0_.instance_id =?   2019-03-22 09:00:34,226 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-启动事务提交   2019-03-22 09:00:34,226 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-在EntityManager上提交JPA事务[SessionImpl(1808876088)]   2019-03-22 09:00:34,294 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:34,294 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:00:34,294 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-找到用于JPA事务的线程绑定的EntityManager [SessionImpl(1808876088)]   2019-03-22 09:00:34,294 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与现有交易   2019-03-22 09:05:46,949 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与事务失败-将现有事务标记为仅回滚   2019-03-22 09:05:46,950 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-在EntityManager上设置JPA事务[SessionImpl(1808876088)]仅回滚   2019-03-22 09:05:46,952 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-参与事务失败-将现有事务标记为仅回滚   2019-03-22 09:05:46,953 [main sessionId:vaultId:userId:origReqUri:] DEBUG common.infrastructure.TransactionManager-在EntityManager上设置JPA事务[SessionImpl(1808876088)]仅回滚   2019-03-22 09:05:53,089 [main sessionId:vaultId:userId:origReqUri:]错误domain.impl.ObjectRepositoryImpl-[INFO-常规]-执行观察器时捕获到异常。由于这是提交后的内容,因此将被跳过!   org.springframework.dao.InvalidDataAccessApiUsageException:执行更新/删除查询;嵌套的异常是javax.persistence.TransactionRequiredException:执行更新/删除查询     在org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:413)     在org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc $ afterThrowing $ org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect $ 1 $ 18a1ac9(JpaExceptionTranslatorAspect.aj:37)

0 个答案:

没有答案