Adapted JPA 2.1 example to latest changes in Spring Data JPA.
Changed method to derive the stored procedure metadata to be named after the stored procedure so that the name doesn't have to be customized on the annotation. Switched to Spring Data JPA master branch artifact as the stored procedure support has been merged recently.
This commit is contained in:
@@ -44,11 +44,11 @@ public interface UserRepository extends CrudRepository<User, Long> {
|
||||
Integer plus1BackedByOtherNamedStoredProcedure(@Param("arg") Integer arg);
|
||||
|
||||
// Directly map the method to the stored procedure in the database (to avoid the annotation madness on your domain classes).
|
||||
@Procedure("plus1inout")
|
||||
Integer derivedStoredProcedureDeclaration(Integer arg);
|
||||
@Procedure
|
||||
Integer plus1inout(Integer arg);
|
||||
}
|
||||
```
|
||||
|
||||
Calling `UserRepository.plus1BackedByOtherNamedStoredProcedure(…)` will execute the stored procedure `plus1inout` using the meta-data declared on the `User` domain class.
|
||||
|
||||
`UserRepository.derivedStoredProcedureDeclaration(…)` will use the stored procedure name declared in the annotation and default to positional parameter binding and expect a single output parameter of the backing stored procedure.
|
||||
`UserRepository.plus1inout(…)` will derive stored procedure metadata from the repository and default to positional parameter binding and expect a single output parameter of the backing stored procedure.
|
||||
@@ -12,7 +12,7 @@
|
||||
<name>Spring Data JPA - JPA 2.1 specific features</name>
|
||||
|
||||
<properties>
|
||||
<spring-data-jpa.version>1.6.0.DATAJPA-455-SNAPSHOT</spring-data-jpa.version>
|
||||
<spring-data-jpa.version>1.6.0.BUILD-SNAPSHOT</spring-data-jpa.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -42,6 +42,6 @@ public interface UserRepository extends CrudRepository<User, Long> {
|
||||
* Directly map the method to the stored procedure in the database (to avoid the annotation madness on your domain
|
||||
* classes).
|
||||
*/
|
||||
@Procedure("plus1inout")
|
||||
Integer derivedStoredProcedureDeclaration(Integer arg);
|
||||
@Procedure
|
||||
Integer plus1inout(Integer arg);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class UserRepositoryIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
public void invokeDerivedStoredProcedure() {
|
||||
assertThat(repository.derivedStoredProcedureDeclaration(1), is(2));
|
||||
assertThat(repository.plus1inout(1), is(2));
|
||||
}
|
||||
|
||||
// This is what it would look like implemented manually.
|
||||
|
||||
Reference in New Issue
Block a user