JPA Eclipselink - Trigger SQL SERVER

Asked

Viewed 287 times

0

I’m having a problem with a Trigger created in SQL SERVER. When I insert the data into the table that starts Trigger directly in SQL SERVER Trigger works normal, however when performed insertion by JPA it presents an error and the rollback.

Follow 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

Someone’s had the same problem?

  • I’m not sure, but by this line of error Internal Exception: com.microsoft.sqlserver.jdbc.Sqlserverexception: A set of results was generated for update. Try replacing Trigger’s select by set.

1 answer

0

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

Select DateAdd(month, @AUX, @VCM)

SQL SERVER ended up being complicated with the handling of the various returns it had from that select. So I took it worked normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.