I am using raiseerror in MS SQL Server exception to throw customized error and it is working fine in database.
But, I am unable to catch MS SQL Server Exception in hibernate. Please find the database & java syntax below.
SQL Server Syntax:-
ALTER PROCEDURE [grantiumSQL].[ERROR_MESSAGE]
(
@ERRMSG NVARCHAR(4000)
)
AS
BEGIN
-- Return if there is no error information to retrieve.
IF ERROR_NUMBER() IS NULL
RETURN;
DECLARE
@ErrorMessage NVARCHAR(4000),
@ErrorNumber INT,
@ErrorSeverity INT,
@ErrorState INT,
@ErrorLine INT,
@ErrorProcedure NVARCHAR(200);
-- Assign variables to error-handling functions that
-- capture information for RAISERROR.
SELECT
@ErrorNumber = ERROR_NUMBER(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(),
@ErrorLine = ERROR_LINE(),
@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-'),
@ErrorMessage = @ERRMSG
RAISERROR
(
@ErrorMessage,
@ErrorSeverity,
1
)WITH NOWAIT;
END;
Java Syntax:-
public void callDeleteStoreProcedure(int workflowProjectId,String status){
boolean shouldCommit = HibernateUtil.beginTxn();
Session session = HibernateUtil.currentSession();
try
{
// query = session.getNamedQuery("deleteWorkflowProject_ora");
Query callStoredProcedure = session.createSQLQuery("{PROCEDUR_NAME(?,?)}");
callStoredProcedure.setInteger(0, prj);
callStoredProcedure.setString(1, status);
callStoredProcedure.executeUpdate();
}catch (HibernateException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
HibernateUtil.commitTxn(shouldCommit);
}
Thanks in advance