JPA: javax.persistence.TransactionRequiredException: Executing an update/delete query

45 views Asked by At

good morning,

I'm trying to make the next UPDATE sentence on my BBDD

    @org.springframework.transaction.annotation.Transactional
    @Modifying
    @Query(value="UPDATE trs_uni.dbo.estadomaquinas SET observacion = ?1 WHERE registro = ?2 ", nativeQuery = true)
    void updateTest(String observacion,  Integer registro);

It's a simple UPDATE, so i should't have any problem with it, the Service im calling updateTest from it includes the annotation @Transactional from the springframework package as you can see here:

@org.springframework.transaction.annotation.Transactional
    public Integer updateTest(String observacion, Integer registro){

        paradasActivasRepository.updateTest(observacion, registro);
        return 1;

    }

Even if I use de annotation on Repository and Service level instead of on the methods I get the next Exception:

org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:402) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]

Any ideas of what I'm doing wrong? Thank you very much

I've tried to delete de @Modifying annotation on the Update and i get this exception (it makes sense, but it actually updates the row on BBDD):

could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet
0

There are 0 answers