native insert query in hibernate + spring data

2020-02-12 00:09发布

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:

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)]

Where am I wrong?

1条回答
我命由我不由天
2楼-- · 2020-02-12 00:39

I had to add nativeQuery = true to @Query

@Query(value = "insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)", nativeQuery = true)
查看更多
登录 后发表回答