1

I am using JDBCTemplate in my existing project and want to switch to Spring-Data. Is there anyway by which I can use native sql as is using spring data jdbc extension without using QueryDSL pattern?

Secondly, Can Spring Data JPA help in this case?

Thanks

user1045445
  • 93
  • 1
  • 10

1 Answers1

2

If I understood right, you want to use Spring Data JPA to execute native SQL.

Assuming you have integrated Spring Data JPA in your project and are using Repositories that implement Spring Data JPA interfaces, you can simply define a method in your repository and annotate it as below :

    @Query(value = "select * from table", nativeQuery = true)
    public void executeMyQuery();

Please look at this to externalize your queries :

How to store @Query sql in external file for CrudRepository?

Community
  • 1
  • 1
souser
  • 796
  • 2
  • 8
  • 25
  • I appreciate. I was looking for Spring Data JDBC extension specifically since I am using complex queries (stored in prop/xml file) and jdbc extension suits my solution. Will this work with JDBC extension too? – user1045445 Jan 26 '15 at 15:38