Is it possible to use raw SQL within a Spring Repository

Webnet picture Webnet · Apr 11, 2013 · Viewed 192.2k times · Source

I need to use raw SQL within a Spring Data Repository, is this possible? Everything I see around @Query is always entity based.

Answer

zagyi picture zagyi · Apr 11, 2013

The @Query annotation allows to execute native queries by setting the nativeQuery flag to true.

Quote from Spring Data JPA reference docs.

Also, see this section on how to do it with a named native query.