Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query

Viewed 8031

I have tried various suggestions on solving the above error but its still there. Below is my repository. How can I solve this?

@Transaction
public interface ApplicationRepository extends JpaRepository<Application, BigInteger> {

    @Modifying
    @Query(nativeQuery = true, value = "update application set transaction_status = :transaction_status where id =:id")
    void updateStatus(@Param("transaction_status") int transaction_status, @Param("id") BigInteger id);
}
1 Answers

Given your ApplicationRepository, I am assuming that you are using Spring JPA.

The exception you are facing to is javax.persistence.TransactionRequiredException.

You have already added @Transactional annotation to the repository, but please make sure that the import which you are using for is org.springframework.transaction.annotation.Transactional, because it seems that you might be using javax.transaction.Transactional.

I also suggest to you to use @Transactional on the class/method of the repository consumer.

Related