gpt4 book ai didi

java - 相当于 spring data jpa 中的 `set @variable = 0`

转载 作者:行者123 更新时间:2023-11-29 16:34:14 25 4
gpt4 key购买 nike

我正在尝试通过 spring data jpa 在 MySQL 上一次性执行以下查询。

    SET @i := 0;
UPDATE tv_episode te SET te.display_episode_no= @i:=@i+1 WHERE te.tv_season_id=season ORDER BY broadcast_date;

我尝试在 StackOverflow 上寻找解决方案,但没有找到。

spring-data-jpa 中的 SET @i := 0; 相当于什么?有没有办法可以在 @Modifying@Query 带注释的方法中执行语句?

最佳答案

您可以通过将 nativeQuery = true 添加到 @Query 来运行 native 查询:

@Modifying
@Query(value = "SET @i := 0;\n" +
"UPDATE tv_episode te SET te.display_episode_no= @i:=@i+1 WHERE te.tv_season_id = :season", nativeQuery = true)
int updateUserSetStatusForName(@Param("season") Integer season);

如果您不想使用 native 查询,您可以传递如下参数:

@Modifying
@Query("update TvEpisode te set te.displayEpisodeNo = :epiodeNo where te.tvSeasonId = :season")
int updateUserSetStatusForName(@Param("epiodeNo") Integer epiodeNo,
@Param("season") Integer season);

关于java - 相当于 spring data jpa 中的 `set @variable = 0`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53706912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com