我使用 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);
}
关于java - JPA事务异常获取真正原因 - 嵌套异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39872706/