java - Hibernate - 处理 SQLException
问题描述
全部,
我正在开发一个将休眠从 4.1.4.FINAL 升级到 5.2.17.FINAL 的项目。我们有一堆使用 org.hibernate.jdbc.Work 执行的 Sybase 存储过程。这些存储过程使用一些有效的错误代码(如 20010)引发错误。引发的错误消息被捕获并用于在 UI 上显示。这是引发错误的 Sybase 语法。
raiserror 20005 'Invalid'
我看到新版本的 hibernate 委托 SQL 异常转换为 JDBCException 层次结构中的特定异常。看 -
org.hibernate.exception.internal.StandardSQLExceptionConverter
如果它没有找到特定的异常,那么它会创建带有默认消息集的 GenericJDBCException。例如见
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork -
Here the SQL exception is caught and the convert method is called with message 'error executing work'. So genericJDBCException.getMessage() will give this message.
我知道 GenericJDBCException.getSQLException().getMessage() 会给出实际的 sql 异常消息。但是改变现有的代码是不可行的。
有没有办法添加我们自己的委托,以便我可以检查错误代码并返回带有 SQLException 消息的异常。或者有没有更好的方法来处理这个?
谢谢
解决方案
推荐阅读
- flutter - Flutter - mainAxisAlignment 不适用于列中的行
- java - Servlet 不适用于 Tomcat 8 中的某些路径
- swift - 多个 if let in Swift
- javascript - 如何在 Odoo-12 销售点覆盖 screen.js 中的 renderElement 函数
- python - 直接在 Python 解释器上打印
- javascript - 如何使用变量值来调用对象属性?
- javascript - Javascript 将所需库设置为模块导出以实现继承
- javascript - Google 应用程序中使用 changeType 的事件对象
- java - 安卓工作室滑翔
- python - 有没有办法将 x,y 坐标转换为灰度矩阵?(Python)