Throwing specific error messages in PLSQL Oracle ... catching hibernation?
2 answers
You can submit custom error messages from PL / SQL code. Error codes -20000 to -20999 are reserved for user-specified error messages.
You do this by calling a function raise_application_error
in your PL / SQL:
raise_application_error(-20001, 'Your error code message here');
This will propagate just like normal Oracle bugs.
Edit:
I am not a Hibernate user, but I found this while trying to find the answer and I think it will lead you on the right track.
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
}
}
+5
source to share
you can use an output parameter on pl / sql and select the output in your code with ParameterMode.OUT
CREATE OR REPLACE procedure proc (number pls_out_put out);
// call output
query.registerStoredProcedureParameter( "pls_out_put", Integer.class, ParameterMode.OUT);`
int result = (Integer) 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);
}
0
source to share