java - 为什么 hibernate 将 HibernateException 更改为(未检查的)RuntimeException

标签 java hibernate exception

我知道在某些版本中,Hibernate 异常被更改为未检查。是什么原因?这是哲学问题还是实践问题?

最佳答案

实用。因此,您不必将有关 Hibernate 的每一项操作都包装在 try catch block 中。

摘自 Java Persistence with Hibernate:

A history of exceptions — Exceptions and how they should be handled always end in heated debates between Java developers. It isn’t surprising that Hibernate has some noteworthy history as well. Until Hibernate 3.x, all exceptions thrown by Hibernate were checked exceptions, so every Hibernate API forced the developer to catch and handle exceptions. This strategy was influenced by JDBC , which also throws only checked exceptions. However, it soon became clear that this doesn’t make sense, because all exceptions thrown by Hibernate are fatal. In many cases, the best a developer can do in this situation is to clean up, display an error message, and exit the application. 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.

关于java - 为什么 hibernate 将 HibernateException 更改为(未检查的)RuntimeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4609870/

相关文章:

java - 当没有给出 catch block 时,正确的语句顺序应该是什么?

java - 什么样的行为会导致异常中断?

Java 和 MySql。哪个异常真正需要 "rollback"

java - Junit:为删除实体的方法编写测试?

c++ - 什么需要特殊的异常类?

java - 如何在 session 中存储检索对象并在之后访问它?

java - spring mvc tomcat错误

Java 字符串到字节数组的错误转换

java - 为什么这个递归斐波那契函数运行得如此糟糕?

java - 从本地文件夹加载应用程序中的图片