0

I have an interface that implements crudrepository. I am using @Query annotations.

I really need an entitymanager to build a native query. What should I do? Should I tear down the interface implementing crudrepository and extend from simplejparepository?

Please advise?

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
Julie
  • 179
  • 2
  • 13

1 Answers1

0

You don't need an entityManager - @Query annotation has a nativeQuery parameter that allows you to do just that! Check Spring Data documentation about it for more examples:

@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1", nativeQuery = true)

If you still need to access the EM directly for some reason, take a look at this answer: https://stackoverflow.com/a/34876232/1563204 or at Spring Data documentation for custom JPA repositories.

Community
  • 1
  • 1
jderda
  • 890
  • 6
  • 18