Search code examples
sqlhibernatespring-data

native insert query in hibernate + spring data


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?


Solution

  • I had to add nativeQuery = true to @Query

    @Query(value = "insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)", nativeQuery = true)