JPA @Query delete 问题

使用JPA去做删除操作,除了remove外很容易想到下面这种做法:

1
2
@Query("delete from Model t where t.id=:id")
public void doDelete(int id);

但上面这个写法会delete失败,加上两个注解即可,如下:

1
2
3
4
@Modifying
@Transactional
@Query("delete from Model t where t.id=:id")
public void doDelete(int id);