Spring Data JPA问题 (更新、保存时需要加上注解事务------@Transactional)

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

上一篇:kubernetes集群搭(kubeadm方式)


下一篇:Mybatis Plus LocalDateTime - InvalidDataAccessApiUsageException