Why does this JPQL fail with message "You have attempted to set a parameter at position 1 which does not exist in this query string"?

huangapple go评论67阅读模式
英文:

Why does this JPQL fail with message "You have attempted to set a parameter at position 1 which does not exist in this query string"?

问题

我有一个继承自 JpaRepository 的接口,其中包含这个定义如下的更新查询:

@Modifying
@Query("UPDATE configuration SET id = replace(id, ?1, ?2) WHERE id LIKE ?3")
void updateId(String replaceThis, String replaceWith, String like);

我始终收到错误消息:“您试图在位置1处设置一个在此查询字符串中不存在的参数,查询字符串为 UPDATE configuration SET id = replace(id, ?1, ?2) WHERE id LIKE ?3”,但我不明白,因为在我放置它的地方,位置1处的参数明明是存在的。我漏掉了什么?

英文:

I have an interface extending JpaRepository containing this update query defined like that:

@Modifying
@Query("UPDATE configuration SET id = replace(id, ?1, ?2) WHERE id LIKE ?3")
void updateId(String replaceThis, String replaceWith, String like);

I get always "You have attempted to set a parameter at position 1 which does not exist in this query string UPDATE configuration SET id = replace(id, ?1, ?2) WHERE id LIKE ?3" error message which I don't understand because parameter at position 1 clearly exists where I put it. What am I missing?

答案1

得分: 2

可以尝试这个查询:

@Query("UPDATE configuration SET id = function('replace', id, ?1, ?2) WHERE id LIKE ?3")
英文:

you can try this query:

   @Query("UPDATE configuration SET id = function('replace',id, ?1, ?2) WHERE id LIKE ?3")?

huangapple
  • 本文由 发表于 2020年9月10日 23:20:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63832819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定