当我们做
session.save()
在hiberbate端它可能会抛出不同的异常。我们需要处理它们吗?我们应该如何处理?
我发现了 save() 的两个实现(在 SessionImpl 和 SessionDelegatorBaseImpl 中),并且在 SessionImpl 的 save() 中它抛出了 hibernate 异常。
谁能给我解释一下这些东西吗?
最佳答案
大多数 Hibernate 异常都是 RuntimeExceptions
,因此只有在需要时才应该处理。
Therefore, starting with Hibernate 3.x, all exceptions thrown by Hibernate are subtypes of the unchecked Runtime Exception, which is usually handled in a single location in an application. This also makes any Hibernate template or wrapper API obsolete.
这可能有帮助why hibernate changed HibernateException to (unchecked) RuntimeException
关于java - 我们应该在保存实体时处理异常吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16274227/