I'm having a hard time getting the return value (integer) from a stored procedure using Hibernate and Java.
My stored procedure is as follows:
create proc dbo.CheckEquipmentAuthorization
@ReplicaId int
as
declare @IDAuthType int
select @IDAuthType = AuthorizationType.IDAuthorizationType from AuthorizationType
inner join ReplicaAuthorization on ReplicaAuthorization.RefIDAuthorizationType = AuthorizationType.IDAuthorizationType
inner join Replica_ReplicaAuthorization on Replica_ReplicaAuthorization.RefIDAuthorization = ReplicaAuthorization.IDAuthorization
inner join Replica on Replica.IDReplica = Replica_ReplicaAuthorization.RefIDReplica
where Replica.IDReplica = @ReplicaId
and GETDATE() between ReplicaAuthorization.AuthBegin and ReplicaAuthorization.AuthEnd
declare @AuthIntValue int
set @AuthIntValue = 10
if (@IDAuthType is not null)
begin
select @AuthIntValue = AuthorizationType.IntValue from AuthorizationType
where AuthorizationType.IDAuthorizationType = @IDAuthType
end
print @AuthIntValue
return @AuthIntValue
I'm trying to get the return value using:
query = session.createSQLQuery(
"exec CheckEquipmentAuthorization(:replicaId)")
.setParameter("replicaId", replicaId);
But it seems I can only get a result table using this, and since no result table is generate from my procedure, nor do I want one to be, it fails.
Is there a way to get that returned value using that createSQLQuery() method?
I'm using Hibernate, Java and SQL Server. The stored procedure is working correctly (I have tested it with a sql client).
Thank you.