Hibernate-将实体引用列表复制到新实体会引发RollbackException

时间:2018-07-31 08:34:54

标签: hibernate jpa java-ee jdbc

我当前面临以下问题:我想复制

的所有引用
@OneToMany
List<Entity> entities;

收集到新实体。但是,当我这样做时,在提交事务时会收到以下异常:

    Caused by: javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction.
    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1243)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
    at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:91) [jboss-as-ejb3-7.5.20.Final-redhat-1.jar:7.5.20.Final-redhat-1]
    ... 109 more
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:56) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:96) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:183) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:83) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.id.enhanced.SequenceStructure$1.getNextValue(SequenceStructure.java:96) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.id.enhanced.OptimizerFactory$NoopOptimizer.generate(OptimizerFactory.java:258) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:369) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.ejb.event.EJB3SaveEventListener.saveWithGeneratedId(EJB3SaveEventListener.java:71) [hibernate-entitymanager-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:683) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:675) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.envers.revisioninfo.DefaultRevisionInfoGenerator.saveRevisionData(DefaultRevisionInfoGenerator.java:83) [hibernate-envers-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.envers.synchronization.AuditProcess.getCurrentRevisionData(AuditProcess.java:129) [hibernate-envers-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:106) [hibernate-envers-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:155) [hibernate-envers-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.envers.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:62) [hibernate-envers-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:748) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:338) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:490) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:118) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93)
    at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1231)
    ... 112 more
Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000460: Error checking for a transaction
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:151)
    at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:69)
    at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70) [hibernate-entitymanager-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:301) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]
    ... 144 more
Caused by: javax.resource.ResourceException: IJ000460: Error checking for a transaction
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:362)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:499)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:143)
    ... 148 more
Caused by: javax.resource.ResourceException: IJ000459: Transaction is not active: tx=TransactionImple < ac, BasicAction: 0:ffff0a00c22b:4e7cd752:5b601bd8:14 status: ActionStatus.ABORT_ONLY >
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:352)
    ... 150 more

我已经检查了是否没有交易。如果没有复制实体列表,则一切都将提交。

这是一个代码段:

final ParentEntity entity = new ParentEntity();
entity.getEntities().addAll(objectToCopyReferencesFrom.getEntities());
this.getEntityManager().persist(entity);

预先感谢。 斯蒂芬

0 个答案:

没有答案