[Spring Data JPA问题]Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException

时间:2021-11-14 20:34:15

JPQL如下:

@Modifying(clearAutomatically = true)
@Query("UPDATE SyncTestFromTKDO SET stuAns = '' where typeId = ?1")
public void updateStuAns(Integer typeid);

项目运行时报错,提示:

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

原因:

update、delete操作涉及到事务机制,需要进行设置

解决方法:

在调用这个方法的service类上加上注解@Transactional(import org.springframework.transaction.annotation.Transactional;)