Java教程

JavaExecuting an update/delete query; nested exception is javax.persistence.TransactionRequiredExcep

本文主要是介绍JavaExecuting an update/delete query; nested exception is javax.persistence.TransactionRequiredExcep,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

[Spring Data JPA问题]

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类上加上注解

import org.springframework.transaction.annotation.Transactional;

@Transactional()
 

这篇关于JavaExecuting an update/delete query; nested exception is javax.persistence.TransactionRequiredExcep的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!