I am attempting to call an Oracle stored function via Spring Data JDBC (NOT JPA but JDBC) with the @Query annotation:
@Repository
public interface UserRepository extends CrudRepository<User, String>{
@Query(value="? = call PKG.get_app_props()")
Object getLoginProperty();
}
Unfortunately, I'm getting an InvalidDataAccessApiUsageException saying "given one prop, but expected 0". I understand just fine that the "? = " means it's expecting something, but I need to get the result of the function call.
However, I'm having a miserable time finding a) an example of using a @Query annotation for a stored function (even procedures are pretty iffy), and b) finding examples for Spring Data JDBC instead of JPA.
I'll be implementing a RowMapper or ResultsetExtractor once I can get SOMETHING back from the function.
Can anyone help?
Exception per request:
org.springframework.dao.InvalidDataAccessApiUsageException: SQL [? = call PKG.get_app_props()]: given 1 parameters but expected 0
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.<init>(PreparedStatementCreatorFactory.java:218)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.<init>(PreparedStatementCreatorFactory.java:197)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory.newPreparedStatementCreator(PreparedStatementCreatorFactory.java:171)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:426)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:399)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:243)
at org.springframework.data.jdbc.repository.query.AbstractJdbcQuery.lambda$singleObjectQuery$1(AbstractJdbcQuery.java:120)
RowMapperorResultsetExtractoronce you retrieve something? If you receive something you don't need to convert anything. Please add the full error to the question. All being said you are probably better of using aSimpleJdbcCallinstead of an@Queryhere.RowMapper(which isn't actually possible) you aren't making it any better and are adding boilerplate again yourself. So you actually loose what you gain with what you are trying. Which is why I suggested aSimpleJdbcCallin the first place. Which would take around the same amount of code you have now.@Queryand it allows specifying a row mapper class or resultsetexractor. Am I misunderstanding the arguments to @Query?JdbcTemplate.callmethod and not theNamedParameterJebcTemplate.queryForObject. As one needs to register in and out parameters for the function (only OUT as there is no input). So it looks like what you want with a Spring Data JDBC Repository is currently not possible.