Spring data reference supports calling stored procedure (from JPA 2.1) but didn't work for me. Therefore I called the stored procedure with a native query:
@Repository
public interface MyEntityRepository extends PagingAndSortingRepository<MyEntity, Long> {
@Query(nativeQuery=true, value="{call GetFoo()}")
Object[] callMyStoredProcedure();
}
Details:
1) We are obliged to write the call in an entity repository. Therefore choose an entity in random (e.g. I used MyEntity) and place there your stored procedure call.
2) The stored procedure with name GetFoo() joins some tables, etc, and returns a row. Its columns are stored in the returned Object[].
PS: For Spring Data and Stored Procedures check the following sites:
- http://blogs.isostech.com/database/jpa-spring-data-awesomeness/
No comments:
Post a Comment