Search code examples
spring-bootjdbctemplate

Spring Boot JdbcTemplate Unable to determine the correct call signature - multiple procedures/functions/signatures


I have a Spring Boot application that uses JdbcTemplate to call a stored procedure named up_RefData_getParticipantBitCrossINTERN

When the application calls the stored procedure, the following exception is thrown:

org.springframework.dao.InvalidDataAccessApiUsageException: Unable to determine the correct call signature - multiple procedures/functions/signatures for 'up_RefData_getParticipantBitCrossINTERN': found [aquadev2.null.up_RefData_getParticipantBitCrossINTERN, aquaprod.null.up_RefData_getParticipantBitCrossINTERN]

My database is MySql 5.x.x and it contains two catalogs (aquadev2 and aquaprod) that both contain the same stored procedure.

The JdbcTemplate should not even know about the aquaprod catalog since I specifically stated which catalog to connect to in application.properties:

spring.datasource.url=jdbc:mysql://<hostname>:3306/aquadev2?serverTimezone=America/New_York

If I hard code which catalog I want in the java code:

SimpleJdbcCall getBitCrossInternal = new SimpleJdbcCall(jdbcTemplate)
        .withProcedureName(STORED_PROC_INTERN).withCatalogName("aquadev2");

It works fine, but this is unacceptable to hard code the catalog name .

Why doesn't the JdbcTemplate recognize the catalog name in the datasource URL?


Solution

  • I never received an answer on why I must specify "catalog" but I did manage to avoid hard coding it and settling for having to specify the catalog in application.properties.

    in application.properties:

    refdataserver.datasource.catalog=${DB}
    

    Create a class called Datasource in package com.XXX.refdataserver Make sure you have getter and setter for catalog and @ConfigurationProperties annotation.

    @Configuration
    @ConfigurationProperties(prefix = "refdataserver.datasource")
    @Validated
    @Getter
    @Setter
    @ToString
    public class Datasource {
       /**
        * Must specify the database in applicaton.properties
        */
       @NotNull(message = "refdataserver.datasource.catalog is mandatory")
       private String catalog;
    }
    

    Create a properties holder Configuration with an instance of Datasource

    @Component("serverProps")
    @Configuration
    @ConfigurationProperties(prefix = "refdataserver")
    @Validated
    @Getter
    @Setter
    @ToString
    public class RefDataServerProperties {
       /** refdataserver.datasource properties */
       private Datasource dataSource;
    }
    

    Then, in any class via autowire, you can retrieve the catalog via the properties configuration.

    @Autowired
    private RefDataServerProperties serverProps;
    ...
    serverProps.getDataSource().getCatalog()