JPA Eclipselink - Trigger SQL SERVER

0

I'm having a problem with a trigger created in SQL SERVER. When I insert the data in the table that initiates the direct trigger in SQL SERVER the trigger works normal, however when done the insertion by JPA it presents an error and of the rollback.

The following is the error:

[EL Warning]: 2016-06-18 12:29:39.144--UnitOfWork(2039736611)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Um conjunto de resultados foi gerado para atualização.
Error Code: 0
Call: INSERT INTO EMPRESTIMO (DATAEMPRESTIMO, EMPRESTIMOMAISTAXA, LIMITEPARCELA, NUMEROPARCELA, NUMEROPARCELAMINIMA, PARCELAMAXIMA, PRIMEIRAPARCELA, SALARIOLIQUIDO, TAXAJUROS, VALOREMPRESTIMO, VALORJUROS, VALORPARCELA, CLIENTE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [13 parameters bound]
Query: InsertObjectQuery(JPA.EmprestimoPOJO@64d8f425)
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Um conjunto de resultados foi gerado para atualização.
Error Code: 0
Call: INSERT INTO EMPRESTIMO (DATAEMPRESTIMO, EMPRESTIMOMAISTAXA, LIMITEPARCELA, NUMEROPARCELA, NUMEROPARCELAMINIMA, PARCELAMAXIMA, PRIMEIRAPARCELA, SALARIOLIQUIDO, TAXAJUROS, VALOREMPRESTIMO, VALORJUROS, VALORPARCELA, CLIENTE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [13 parameters bound]
Query: InsertObjectQuery(JPA.EmprestimoPOJO@64d8f425)
Erro ao gravar no banco de dados

TRIGGER:

CREATE TRIGGER TRG_PARCELAS 
ON EMPRESTIMO
AFTER INSERT

AS

    --valor a serem inseridos na inserted

    DECLARE @PG         BIT
    DECLARE @VLR        FLOAT
    DECLARE @VCM        DATE
    DECLARE @IDEMPR     INT
    DECLARE @NPARCELA   INT
    DECLARE @AUX        INT

BEGIN

    --Pega valores da linha inserida de emprestimo
    SELECT  @VLR = VALORPARCELA, @VCM = PRIMEIRAPARCELA, @IDEMPR = ID, @NPARCELA = NUMEROPARCELA
    FROM INSERTED

    --Set AUX como 0
    SET @AUX = 0
    SET @PG = 0

    WHILE @AUX < @NPARCELA BEGIN

        Select DateAdd(month, @AUX, @VCM)
        INSERT INTO PARCELA (PAGO, VALOR, VENCIMENTO, EMPRESTIMO_ID) 
        VALUES (0, @VLR, @VCM, @IDEMPR)

        SET @AUX = @AUX + 1

        END

END

Has anyone ever had the same problem?

    
asked by anonymous 18.06.2016 / 17:47

1 answer

0

The problem was in the following line that performed select within the loop.

Select DateAdd(month, @AUX, @VCM)

SQL SERVER ended up getting complicated with the treatment of the various returns that had of that select. So I took off worked normally.

    
07.07.2016 / 20:41