StoredProcedureQuery不返回任何内容

时间:2018-12-24 15:27:30

标签: java sql jpa java-stored-procedures

我有一个存储过程可以更新或插入数据库。

UpdateMnoMsisdnStatus.sql:

ALTER PROCEDURE [dbo].[UpdateMnoMsisdnStatus]
(@Msisdn VARCHAR(20),
@MnoRef VARCHAR(255),
@Status VARCHAR(15)
)
AS
BEGIN
BEGIN TRAN
BEGIN TRY

    IF NOT EXISTS (SELECT /* F4BB6573-5C43-498D-8DE7-65610801F925 */ NULL FROM dbo.MsisdnStock WHERE Msisdn = @Msisdn)
    BEGIN
        RAISERROR('Msisdn does not exist in stock', 16, 1)
    END

    IF EXISTS (SELECT /* 61FB92B0-F811-4022-9849-8E51C20291E9 */ NULL FROM dbo.MnoMsisdnStock WHERE Msisdn = @Msisdn AND MnoRef = @MnoRef)
        BEGIN
            UPDATE dbo.MnoMsisdnStock SET /* 9F97046E-F65D-46A2-8D99-61DC56A45A3D */
                Status = @Status ,
                StatusDate = (case when NOT @Status='ToBeRestored' then  GETDATE() end)
    WHERE Msisdn = @Msisdn AND MnoRef = @MnoRef
        END
    ELSE
        BEGIN
            INSERT INTO MnoMsisdnStock (Msisdn, MnoRef, Status, StatusDate)
            /* CD15DACD-5097-41BC-B9A7-3AF1F7730D04 */
            VALUES
            (@Msisdn, @MnoRef, @Status, GETDATE())

        END

    UPDATE dbo.MsisdnStock SET /* 6AAB7C5D-B075-400F-9B48-5FF227E02183 */
        Status = 'NA' ,
        StatusDate = GETDATE()
WHERE Msisdn = @Msisdn

    COMMIT

END TRY
BEGIN CATCH
    IF XACT_STATE() <> 0
        ROLLBACK TRANSACTION

    DECLARE @errormessage varchar(max)
    SELECT  @errormessage=ERROR_MESSAGE()
    RAISERROR(@errormessage, 16, 1)
END CATCH
END

我在Java中这样调用此过程(CALL_UPDATE_MNO_MSISDN_STATUS = UpdateMnoMsisdnStatus):

 public int updateMnoMsisdnStatus(String msisdn, String mnoRef, String newStatus){

    LOG.info("updateMnoMsisdnStatus with:\n msisdn: {}\n mnoRef: {}\n status: {}", msisdn, mnoRef, newStatus);
    StoredProcedureQuery sp = entityManager.createStoredProcedureQuery(CALL_UPDATE_MNO_MSISDN_STATUS)
            .registerStoredProcedureParameter(MSISDN, String.class, ParameterMode.IN)
            .registerStoredProcedureParameter(MNO_REF, String.class, ParameterMode.IN)
            .registerStoredProcedureParameter(STATUS, String.class, ParameterMode.IN)
            .setParameter(MSISDN, msisdn)
            .setParameter(MNO_REF, mnoRef)
            .setParameter(STATUS, newStatus);
    int updated = sp.executeUpdate();

    LOG.info("Updated {} Msisdn to status {}", updated, newStatus);

    return updated;
}

当我通过SQL Server Management Studio运行此过程时,它运行良好。但 当我通过Rest服务运行它时,它会在此级别进行种植,而没有返回任何int updated = sp.executeUpdate();

有什么想法吗?

0 个答案:

没有答案