gpt4 book ai didi

java - 使用 Java 和 Hibernate 从存储过程获取返回值(标量),而不是结果表

转载 作者:行者123 更新时间:2023-11-29 03:46:45 25 4
gpt4 key购买 nike

我很难从使用 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 客户端对其进行了测试)。

谢谢。

最佳答案

这似乎是 this 的副本.您是否映射了存储过程的标量返回类型?您是否正在转换为该返回类型?

关于java - 使用 Java 和 Hibernate 从存储过程获取返回值(标量),而不是结果表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10574095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com