是否有可能在PL/SQL oracle存储过程中抛出一个特定的错误消息,并在被调用时在Hibernate中捕获它?在PLSQL中抛出特定的错误消息Oracle ...在冬眠中捕获?
2
A
回答
5
您可以从PL/SQL代码中抛出用户定义的错误消息。 -20000到-20999之间的错误代码保留给用户指定的错误消息。
通过调用你的PL/SQL中的raise_application_error
功能做到这一点:
raise_application_error(-20001, 'Your error code message here');
这就像正常的Oracle错误传播。
编辑:
我不是休眠的用户,但我发现这一点的同时试图寻找一个答案,我认为这会导致你在正确的道路。
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
}
}
0
你可以在PL/SQL中使用输出参数,并使用ParameterMode.OUT
挑输出在代码中创建或更换过程PROC(pls_out_put出数);
//调用输出
query.registerStoredProcedureParameter("pls_out_put", Integer.class, ParameterMode.OUT);`
INT结果=(整数)query.getOutputParameterValue( “pls_out_put”);
if (result==1){
message = new FacesMessage(FacesMessage.SEVERITY_INFO, "user defined message", "user defined message");
FacesContext.getCurrentInstance().addMessage(null, message);
} else if(result==0) {
message = new FacesMessage(FacesMessage.SEVERITY_INFO, "User defined message", "user defined message");
FacesContext.getCurrentInstance().addMessage(null, message);
}
相关问题
- 1. 冬眠抛出MappingException
- 2. 错误在冬眠
- 3. 在global.asax中捕获特定错误
- 4. 在PLSQL块内部捕获错误
- 5. 在java中捕获xsl:消息输出
- 6. Oracle plsql捕获异常
- 7. 冬眠奇怪的错误在咨询
- 8. 在OpenFileDialog框中取消抛出错误
- 9. 如何捕获在Vue.JS SPA中抛出的所有错误
- 10. 将validatescript中的错误捕获到自定义错误消息中
- 11. 在IE8中jQuery“异常抛出并未捕获”错误
- 12. 如何在JSP中捕获和抛出错误
- 13. 冬眠HQL元素错误
- 14. 冬眠懒真实错误
- 15. 未捕获的异常“抛出:DOMException”有消息“未找到错误”
- 16. 在oracle中获取来自oracle的dbms输出消息
- 17. 如何在Relay中捕获GraphQL错误消息?
- 18. 在多行错误消息中捕获两个字符串
- 19. Angular2 - 捕获异常并在视图中显示错误消息
- 20. 在Postman Body中捕获外部API错误消息
- 21. 捕获无效的xml错误消息
- 22. 使用jquery抛出错误消息
- 23. mq_receive抛出错误说消息太长
- 24. 分页中的Oracle/PLSQL错误
- 25. UncaughtErrorEvent捕获ErrorEvents但不抛出错误
- 26. Java抛出错误和捕获NullPointerException
- 27. 关于冬眠与oracle
- 28. Windows 7捕获睡眠/挂起消息
- 29. 在YouTube中获取“invalidCategoryId”错误消息
- 30. 抛出抛出的错误
我该如何捕捉到冬眠? – Egg 2009-10-09 14:52:50
'org.hibernate.exception.GenericJdbcException'是一个hibernate异常(https://www.hibernate.org/hib_docs/v3/api/org/hibernate/exception/GenericJDBCException.html)。赶上它。 – 2009-10-09 15:30:07
不错的作业RC,应该是enuogh – Egg 2009-10-09 15:37:24