JPA更新報錯:Modifying queries can only use void or int/Integer as return type!

報錯信息:org.springframework.dao.InvalidDataAccessApiUsageException: Modifying queries can only use void or int/Integer as return type!

代碼:

@Modifying
@Transactional
@Query(value = "update Xxx x set x.status=0 where x.id=1")
Xxx upd();

問題:jpa手寫更新語句時,返回值必須爲void 或者 int/Integer

處理後代碼

@Modifying
@Transactional
@Query(value = "update Xxx x set x.status=0 where x.id=1")
Integer upd();

或者

@Modifying
@Transactional
@Query(value = "update Xxx x set x.status=0 where x.id=1")
int upd();

或者

@Modifying
@Transactional
@Query(value = "update Xxx x set x.status=0 where x.id=1")
void upd();

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章