休眠-处理SQLException

时间:2018-06-21 18:49:10

标签: java hibernate

全部

我正在研究一个将休眠从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中返回带有消息的异常。还是有更好的方法来解决这个问题?

谢谢

0 个答案:

没有答案