是否可以在 PL/SQL oracle 存储过程中抛出特定的错误消息,并在调用它时在 Hibernate 中捕获它?
您可以从 PL/SQL 代码中抛出用户定义的错误消息。 -20000 到 -20999 之间的错误代码保留用于用户指定的错误消息。
您可以通过调用raise_application_error
PL/SQL 中的函数:
raise_application_error(-20001, 'Your error code message here');
这将像正常的 Oracle 错误一样传播。
Edit:
我不是 Hibernate 的用户,但我在尝试寻找答案时发现了这一点,我认为它会引导您走上正确的道路。
try
{
// some hibernate calls
}
catch (GenericJdbcException ge)
{
if(ge.getCause() != null && ge.getCause() instanceof SQLException)
{
SQLException se = (SQLException)ge.getCause();
// *****************************************************************
// NOTE: THIS will be where you check for your customer error code.
// *****************************************************************
if(se.getErrorCode() == -20001)
{
// your error handling for this case
}
else
{
throw ge; // do not swallow unhandled exceptions
}
}
else
{
throw ge // do not swallow unhandled exceptions
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)