使用JPA中@Query 注解实现update 操作

使用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) 自动清除实体里保存的数据。
posted @ 2017-05-17 10:47  幕三少  阅读(2643)  评论(0编辑  收藏  举报