我很难从使用 Hibernate 和 Java 的存储过程中获取返回值(整数)。
我的存储过程如下:
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
我正在尝试使用以下方法获取返回值:
query = session.createSQLQuery(
"exec CheckEquipmentAuthorization(:replicaId)")
.setParameter("replicaId", replicaId);
但似乎我只能使用它获得一个结果表,并且由于我的过程没有生成结果表,我也不希望生成一个结果表,所以它失败了。
有没有办法使用 createSQLQuery() 方法获取返回值?
我正在使用 Hibernate、Java 和 SQL Server。存储过程工作正常(我已经使用 sql 客户端对其进行了测试)。
谢谢你。