码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot-JPA删除不成功,只执行了查询语句

时间:2020-05-13 17:03:30      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:tran   lock   sel   语句   from   删除   spring   查询语句   where   

今天使用JPA自定义了一个删除方法deleteByUserIdAndCommentId发现并没有删除掉对应的数据,只执行了查询语句

Hibernate: select good0_.id as id1_6_, good0_.commentId as commenti2_6_, good0_.userId as userid3_6_ from tbl_good good0_ where good0_.userId=? and good0_.commentId=?

解决方法:

在删除方法前加注解@Transactional即可

再次执行时会正常执行

Hibernate: select good0_.id as id1_6_, good0_.commentId as commenti2_6_, good0_.userId as userid3_6_ from tbl_good good0_ where good0_.userId=? and good0_.commentId=?
Hibernate: delete from tbl_good where id=?
Hibernate: select comment0_.id as id1_3_0_, comment0_.articleId as articlei2_3_0_, comment0_.ccomment as ccomment3_3_0_, comment0_.goodNum as goodnum4_3_0_, comment0_.userId as userid5_3_0_, comment0_.userType as usertype6_3_0_ from tbl_comment comment0_ where comment0_.id=?

参考链接:SpringBoot系列教程JPA之delete使用姿势详解

SpringBoot-JPA删除不成功,只执行了查询语句

标签:tran   lock   sel   语句   from   删除   spring   查询语句   where   

原文地址:https://www.cnblogs.com/charlottepl/p/12883054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!