【发布时间】:2018-12-03 09:39:43
【问题描述】:
我目前正在学习在 hibernate 中编写代码并浏览一些博客。我遇到了以下内容 -
"JDBC API throws SQLException that is a checked exception, so we need to write a lot of try-catch block code. Most of the times it’s redundant in every JDBC call and used for transaction management. Hibernate wraps JDBC exceptions and throw JDBCException or HibernateException un-checked exception, so we don’t need to write code to handle it. "
我知道 SQL 异常是编译时异常,需要处理。但我没有得到包装检查异常并将其作为非检查异常抛出的概念。如果我们可以将检查转换为非检查异常检查异常,那么为什么我们不能对Java中的每个检查异常都做同样的事情。我知道我在这里遗漏了一些逻辑,但请帮我解决这个问题。另外, 有人能解释一下这样做的真正优势吗?
【问题讨论】:
标签: java hibernate jdbc exception-handling