java - JPA事务异常获取真正原因 - 嵌套异常

标签 java sql jpa exception openjpa

我使用 openjpa 并使用存储和提交。

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.
...

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

谢谢

最佳答案

有同样的问题,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

关于java - JPA事务异常获取真正原因 - 嵌套异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39872706/

相关文章:

java - 使用 JGit 获取远程存储库的默认分支

mysql - 开始按特定行条件进行查询

mysql - SQL通过使用同一个表组合3个查询

java - 如何为 Seam/JPA( hibernate )创建 DAO 类?

java - 读取rcon命令响应

Java intellij 剪贴板备份

java - 如何在更新 parent 时删除 child ?

java - Hibernate不允许删除子元素

java - 带注解的代码风格

sql - 如何用SQL标记 "transitive groups"?