SpringBoot Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException错误的处理方法
Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
在用Spring JPA的时候,用到了@Query注解,在自定义INSERT语句的时候出现了问题:
@Transactional
public interface ApplicationRepository extends JpaRepository<Application, BigInteger> {
@Modifying
@Query(value = "INSERT INTO report(aaa,bbb) VALUES (?1, ?2)",nativeQuery = true)
void InsertDataIntoReport(String s1,String s2);
}
报错:Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query。
解决方案就是在该接口前加上另一个注解
@Transactional