我需要更新 mysql 表中的字符串值。为此,我编写了如下方法。
@Repository
public interface NotificationRepository extends JpaRepository<Notification, Long> {
@Modifying
@Query("update Notification msg set msg.message = ?1 where msg.applicationUser.id = ?2")
String createNewNotification(String message, Long id);
}
我得到以下异常。
java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
我不能更新表中的字符串值吗?只有 void 或 int 是可能的?。是这个意思吗?我该如何处理这个异常?请帮忙。
最佳答案
正如错误所述,修改查询只能使用 void 或 int/Integer 作为返回类型
,您只能返回 void 或表示查询更新了多少行的整数/int。
改变它,应该可以正常工作。
@Modifying
@Query("update Notification msg set msg.message = ?1 where msg.applicationUser.id = ?2")
void createNewNotification(String message, Long id);
关于尝试在 JpaRepository 中使用 @Query 时出现 java.lang.IllegalArgumentException :Modifying queries can only use void or int/Integer as return type!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46359905/