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

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.