【问题标题】:JPA transaction exception getting real cause - nested exceptionsJPA 事务异常得到真正的原因 - 嵌套异常
【发布时间】:2017-02-13 19:46:48
【问题描述】:

我使用 openjpa 并使用 store 和 commit。

Commit 有时会引发异常,但我无法获得更高的精度。

有时,我猜这是完整性问题(在同一日期存储两次)。

错误信息和堆栈是:

The transaction has been rolled back.  See the nested exceptions for details on the errors that occurred.
<openjpa-2.4.1-r422266:1730418 fatal store error> org.apache.openjpa.persistence.RollbackException: The transaction has been rolled back.  See the nested exceptions for details on the errors that occurred.
...

但是在哪里可以找到更详细的原因,或者如何获得嵌套异常

谢谢

【问题讨论】:

  • 异常在哪里被捕获并发送到记录器?我想你可能只给了它消息,而不是异常本身,所以它没有显示堆栈和嵌套异常。
  • 我同意前面的评论。异常堆栈应该有更多内容,并且应该有“由”信息引起的。查看系统输出或日志以获取更多详细信息,启用 OpenJPA 跟踪,或在捕获异常时执行“printStackTrace()”。
  • @coladict stacktrace is FailedObject: org.gramaco.Regle@1cb4f5f at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:595) 并调用:...不是更有用

标签: java sql jpa exception openjpa


【解决方案1】:

遇到同样的问题,JPA 提交嵌套了我的 JPA 持久调用中的异常并将它们掩埋,因为我只使用了 e.getMessage()

public static List<String> getExceptionMessageChain(Throwable throwable) {
   List<String> result = new ArrayList<String>();
   while (throwable != null) {
      result.add(throwable.getMessage());
      throwable = throwable.getCause();
   }
   return result; //["THIRD EXCEPTION", "SECOND EXCEPTION", "FIRST EXCEPTION"]
}

catch(Exception e) {
   // JPA Exceptions can be nested, need to get entire chain
   getExceptionMessageChain(e).forEach(System.out::println);
}

来源: Get detail messages of chained exceptions Java

【讨论】:

    猜你喜欢
    • 2020-05-11
    • 2014-06-03
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2021-09-02
    • 2013-04-15
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多