Skip to content
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

spring-jdbc don't set out parameter name from metadata for Postgresql function after issue#25399 #25588

Closed
ddrko22 opened this issue Aug 14, 2020 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Milestone

Comments

@ddrko22
Copy link

ddrko22 commented Aug 14, 2020

Affects: 5.2.8.RELEASE

When using PostgreSQL driver 42.2.11 and higher and spring-jdbc version 5.2.8.RELEASE and calling Postgresql function then CallMetaDataContext.actualFunctionReturnName from function metadata is not set.
Related to issue # 25399 there was a split in GenericCallMetaDataProvider:

function?
databaseMetaData.getFunctionColumns (metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null):
databaseMetaData.getProcedureColumns (metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null)

And for functions it returns columnType = 4, previously it returned columnType = 5.

Because of this, the condition is not met in CallMetaDataContext.reconcileParameters:

if (meta.isReturnParameter()) {
        // DatabaseMetaData.procedureColumnReturn or possibly procedureColumnResult
        if (!isFunction() && !isReturnValueRequired() && paramName != null &&
                provider.byPassReturnParameter(paramName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Bypassing meta-data return parameter for '" + paramName + "'");
            }
        }
        else {
            String returnNameToUse =
                    (StringUtils.hasLength(paramNameToUse) ? paramNameToUse : getFunctionReturnName());
            workParams.add(provider.createDefaultOutParameter(returnNameToUse, meta));
            if (isFunction()) {
                setFunctionReturnName(returnNameToUse);
                outParamNames.add(returnNameToUse);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Added meta-data return parameter for '" + returnNameToUse + "'");
            }
        }
    }

and setFunctionReturnName is not called. It is not executed because isReturnParameter looks like:

public boolean isReturnParameter() {
		return (this.parameterType == DatabaseMetaData.procedureColumnReturn ||
				this.parameterType == DatabaseMetaData.procedureColumnResult);
	}

Only the type of parameters for the procedure are checked.

Because of this, the output parameter for the function is passed in the metadata as returnValue, setFunctionReturnName is not called, and spring uses the default name return, and does not find such a parameter in the results.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 14, 2020
@ddrko22 ddrko22 changed the title spring-jdbc don't set out parameter name from metadata for Postgresql function after issuer#25399 spring-jdbc don't set out parameter name from metadata for Postgresql function after issue#25399 Aug 14, 2020
@benht-nps
Copy link

benht-nps commented Sep 7, 2020

I've found the same issue and can add a little more detail.

Looks like GenericCallMetaDataProvider.processProcedureColumns first identifies it as a function rather than a procedure.

PgDatabaseMetaData.getFunctionColumns (ie the Postgresql driver) sets the return type to java.sql.DatabaseMetaData.functionReturn now (which has magic number 4 whereas in the previous driver it was set to DatabaseMetaData.procedureColumnReturn with magic number 5).

CallMetaDataContext.reconcileParameters calls CallParameterMetaData.isReturnParameter which still only looks for the procedure types, not function types.

It can't simply look for both because the numbers would conflict. It looks like it needs an extra parameter to tell it if it's a procedure or a function.

@jhoeller jhoeller self-assigned this Sep 7, 2020
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 7, 2020
@jhoeller jhoeller added this to the 5.2.9 milestone Sep 7, 2020
@benht-nps
Copy link

Nice one, thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants