当我想在数据库中插入行时,我遇到一个JPA异常的问题我得到了这个异常:
javax.persistence.RollbackException: Exception [EclipseLink-7124] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: An unsuccessful writeChanges() has been called on this UnitOfWork. Given the danger that partial changes have been written to the datastore but not rolled back (if inside external transaction), the only supported operations now are release, global transaction rollback, any non-object level query or SQLCall execution. The operation commit was attempted.
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
at database.TarpineManager.commitTransaction(TarpineManager.java:23)
at gijos.InsertToDB.insertLink(InsertToDB.java:57)
at gijos.LygiagretusIrasymas.run(LygiagretusIrasymas.java:26)
Caused by: Exception [EclipseLink-7124] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: An unsuccessful writeChanges() has been called on this UnitOfWork. Given the danger that partial changes have been written to the datastore but not rolled back (if inside external transaction), the only supported operations now are release, global transaction rollback, any non-object level query or SQLCall execution. The operation commit was attempted.
at org.eclipse.persistence.exceptions.ValidationException.unitOfWorkAfterWriteChangesFailed(ValidationException.java:1802)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1119)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
... 4 more
答案 0 :(得分:3)
您有一个javax.persistence.RollbackException
仅当EntityTransaction.commit()失败时才会引发此问题
EclipseLink中的根本原因是org.eclipse.persistence.exceptions.ValidationException在此UnitOfWork上调用了不成功的writeChanges()。 考虑到已经写入部分更改的危险 数据存储但没有回滚(如果在外部事务内), 现在只支持的操作是发布,全局事务 回滚,任何非对象级别查询或SQLCall执行。该 尝试进行操作提交。
到目前为止,您需要提供一些代码或事务描述。
我想也许你: 1.启动事务,更新/持久化数据,提交失败,收到RollbackException 2.继续在相同的持久化上下文中使用相同的实体对象,并接收另一个RollbackException。这是非法的。第一次收到RollbackException时,必须清除持久性上下文并重新开始:
如果是这样:在错误处理代码中使用EntityManager.clear()
,然后在开始新事务之前重新检索对象。