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

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;)

 

posted @ 2017-09-27 11:45  小猴子爱吃桃  阅读(11515)  评论(1编辑  收藏  举报