-1

当我想在数据库中插入行时,我遇到了一个 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
4

1 回答 1

3
  1. 你有一个 javax.persistence.RollbackException

  2. 这仅在 EntityTransaction.commit() 失败时引发

  3. EclipseLink 中的根本原因是 org.eclipse.persistence.exceptions.ValidationException 在此 UnitOfWork 上调用了不成功的 writeChanges()。鉴于部分更改已写入数据存储但未回滚(如果在外部事务中)的危险,现在唯一支持的操作是发布、全局事务回滚、任何非对象级查询或 SQLCall 执行。已尝试操作提交。

到目前为止,您需要提供一些代码或一些交易描述。

我想也许你: 1. 开始一个事务,更新/持久化数据,提交失败,收到一个 RollbackException 2. 在相同的持久性上下文中继续使用相同的实体对象并收到另一个 RollbackException。这是非法的。第一次收到 RollbackException 时,必须清除持久性上下文并重新开始:

如果这是 try:EntityManager.clear()在错误处理代码中使用,则在开始新事务之前重新检索对象。

于 2012-11-02T03:35:40.513 回答