If JPA prompts executing an update / delete query, it must be because @ transactional and @ modifying are not added to the service layer.
Abnormal scene
When spring-boot2 + JPA performs add modify delete operation:
public interface UserRepository extends JpaRepository<User , Integer>{
@Modifying
@Query(value="update User c set c.state = ?1,c.lastupdatetime = ?2 where c.user_no= ?3")
void updateUser(int state,Date nowDate,String user_no);
}
Exception: executing an update / delete query
Solution
Because JPA requires “no transaction support, update and delete operations cannot be performed”.
So on the other hand, @ transactional must be added to the service layer or repository layer to represent that this is a transaction level operation. Addition, deletion, modification and query are all transaction level except for query. It is OK to regard this as a specification.