当前位置: 移动技术网 > IT编程>开发语言>Java > 使用JPA中@Query 注解实现update 操作方法(必看)

使用JPA中@Query 注解实现update 操作方法(必看)

2019年07月22日  | 移动技术网IT编程  | 我要评论

使用jpa中@query 注解实现update 操作,代码如下:

@transactional

@modifying(clearautomatically = true)

@query(value = "update info p set p.status =?1 where p.id = ?2",nativequery = true)
 int updatestatusbyid( string status,  string id);

备注:

1、更新info表下指定id的status字段, 这里使用了原生的sql语句。

2、@transactional 注解用于提交事务,若没有带上这句,会报事务异常提示。

3、@modifying(clearautomatically = true) 自动清除实体里保存的数据。

以上这篇使用jpa中@query 注解实现update 操作方法(必看)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网