meridbt
meridbt

Reputation: 405

Pass SQL statement to JPA @Query

Is there a way to pass the whole sql statement or a part of it to @Query annotation?

@Modifying
@Query(value = "INSERT INTO my_table :query", nativeQuery = true)
@Transactional
void test(@Param("query") String query);

Upvotes: 0

Views: 1159

Answers (1)

Mihael Mihov
Mihael Mihov

Reputation: 151

I think a viable option for you would be to use the entity manager, instead of the repository. You can do it using NativeQuery and its executeUpdate method. Please check:

Inserting in my JPA using entity manager native query

Upvotes: 1

Related Questions