Skip to content

DATAJPA-1657 - @Procedure annotation doesn't work with cursors (NULL when using REF_CURSOR) and ResultSets that don't come from cursors #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* @author Christoph Strobl
* @author Nicolas Cirigliano
* @author Jens Schauder
* @author Gabriel Basilio
*/
public abstract class JpaQueryExecution {

Expand Down Expand Up @@ -300,6 +301,7 @@ protected Object doExecute(AbstractJpaQuery query, JpaParametersParameterAccesso
*/
static class ProcedureExecution extends JpaQueryExecution {

private static final String NO_SURROUNDING_TRANSACTION = "You're trying to execute a @Procedure method without a surrounding transaction that keeps the connection open so that the ResultSet can actually be consumed. Make sure the consumer code uses @Transactional or any other way of declaring a (read-only) transaction.";
/*
* (non-Javadoc)
* @see org.springframework.data.jpa.repository.query.JpaQueryExecution#doExecute(org.springframework.data.jpa.repository.query.AbstractJpaQuery, java.lang.Object[])
Expand All @@ -311,9 +313,19 @@ protected Object doExecute(AbstractJpaQuery jpaQuery, JpaParametersParameterAcce

StoredProcedureJpaQuery storedProcedureJpaQuery = (StoredProcedureJpaQuery) jpaQuery;
StoredProcedureQuery storedProcedure = storedProcedureJpaQuery.createQuery(accessor);
storedProcedure.execute();

return storedProcedureJpaQuery.extractOutputValue(storedProcedure);
boolean returnsResultSet = storedProcedure.execute();

if(returnsResultSet) {
if(!SurroundingTransactionDetectorMethodInterceptor.INSTANCE.isSurroundingTransactionActive())
throw new InvalidDataAccessApiUsageException(NO_SURROUNDING_TRANSACTION);

List result = storedProcedure.getResultList();
return result.size() == 1
&& !storedProcedureJpaQuery.getQueryMethod().isCollectionQuery() ? result.get(0) : result;
}

return storedProcedureJpaQuery.extractOutputParametersValues(storedProcedure);
}
}

Expand Down
Loading