英文:
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")?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论