hibernate + spring数据中的本机插入查询 [英] native insert query in hibernate + spring data
本文介绍了hibernate + spring数据中的本机插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将以下代码添加到 spring data jpa 存储库:
I try to add the following code to a spring data jpa repository:
@Query("insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)")
void insertLinkToActivity(long commitId, long activityId);
但一个应用程序无法启动异常:
But an app can't start with the exception:
原因:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:第 1 行第 59 列附近的 VALUES [插入 commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)]
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: VALUES near line 1, column 59 [insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)]
我哪里错了?
推荐答案
我必须将 nativeQuery = true
添加到 @Query
@Query(value = "insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)", nativeQuery = true)
这篇关于hibernate + spring数据中的本机插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文