I'm trying to call database stored procedure through CrudRepository
method (spring-jpa).
This is the code of my repository
public interface TestRepo extends JpaRepository<NewsContainer, Long> {
@Procedure(procedureName = "ncMaxVisualisations")
public Long getMaxNumberOfVisualisations();
}
This is the code of class test
public class RankingTest {
private Logger logger = Logger.getLogger(RankingTest.class);
@Autowired
TestRepo repo;
@Autowired
EntityManager em;
@Test
public void testWithEM(){
StoredProcedureQuery store = em.createStoredProcedureQuery("ncMaxVisualisations");
int visualisations = (int) store.getSingleResult();
System.out.println(visualisations);
}
@Test
public void testWithRepository(){
System.out.println(repo.getMaxNumberOfVisualisations());
}
}
The output of test is
testWithRepository()
Hibernate: {call ncMaxVisualisations(?)}
2014-10-24 17:47:28 WARN SqlExceptionHelper:144 - SQL Error: 0, SQLState: S1009
2014-10-24 17:47:28 ERROR SqlExceptionHelper:146 - Parameter number 1 is not an OUT parameter
testWithEM()
Hibernate: {call ncMaxVisualisations()}
50
If I call stored procedure with repository it waits parameter, while if I call it using EntityManager it works fine. Why?
Thanks for your support.
Regards. Mauro