Skip to content

Doc: ParameterMetaData.getParameterType performance on Oracle 12c [SPR-16139] #20687

Closed

Description

@spring-projects-issues

Adam Sojka opened SPR-16139 and commented

After upgrading from Spring 4.3 to 5.0.1 the NamedParameterJdbcTemplate.batchUpdate call results in an exception ORA-01000: maximum open cursors exceeded when using with Oracle 12c.

The batchUpdate is updating batches of 250 records.

The applications code hasn't changed in method where exception is being thrown.

@SuppressWarnings("unchecked")
    public int[] saveBatchOutputs(final String updateSql, final List<Map<String, Object>> batchValuesList) {
        Map<String, Object>[] batchValues = new Map[batchValuesList.size()];
        batchValues = batchValuesList.toArray(batchValues);
        return namedParameterJdbcTemplate.batchUpdate(updateSql, batchValues);
    }

In the method the updateSql is predefined and the batchValuesList is up to 250 elements in size.


Affects: 5.0.1

Issue Links:

Referenced from: commits daee6ee

Activity

  1. spring-projects-issues commented on Oct 31, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    There has been quite a bit of JDBC baseline upgrading in Spring Framework 5.0, so maybe this is a side effect... Any insight (or even guess) into where the different behavior might be caused?

  2. spring-projects-issues commented on Nov 1, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Adam Sojka commented

    I have just verified that rolling back spring-jdbc to 4.3.10 resolved the issue.

  3. spring-projects-issues commented on Nov 2, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Adam Sojka commented

    I couldn't find anything else causing the issue, rollback did the job. I rolled back spring-jdbc alone leaving other spring libraries at version 5.0.1.
    I am using ojdbc7.jar driver for Oracle 12c version 12.1.0.2

  4. spring-projects-issues commented on Nov 14, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I have a suspicion that this is the same effect as with #19196... a workaround which we removed in 5.0 as part of our JDBC baseline upgrade.

    You could try setting spring.jdbc.getParameterType.ignore=true, either as a system property or in a spring.properties file in the root of the classpath. If this is known to help, we may consider reintroducing the workaround to 5.0's streamlined variant of StatementCreatorUtils.setNull.

    That said, see my comment in #19196: Recent Oracle 12c drivers should not expose that cursor leak anymore. If an Oracle driver upgrade helps, that would also be great to know!

  5. spring-projects-issues commented on Nov 15, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Adam Sojka commented

    I have replaced the existing driver with ojdbc8.jar version 12.2.0.1 which fixed the problem. I was no longer getting maximum open cursors exception and the process completed successfully.

    The only problem is the performance. The batch update operation used to take 0.5 seconds for 250 records but now it takes 6 seconds instead. After rolling back to spring-jdbc 4.3.10.RELEASE the timings where back to normal - 0.5 second (using the new Oracle driver).

    Overall the new JDBC driver does address the issue of the exception but there is a performance problem now.

  6. spring-projects-issues commented on Nov 15, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Thanks for the feedback, that's good to know!

    For the performance part of the problem, does it help to set spring.jdbc.getParameterType.ignore=true as suggested above?

  7. spring-projects-issues commented on Nov 16, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Adam Sojka commented

    Yes, after adding spring.properties with spring.jdbc.getParameterType.ignore=true the performance issue was resolved.

    In Summary to resolve the issue one need to:

    1. Upgraded Oracle JDBC driver to ojdbc8.jar version 12.2.0.1
    2. Create spring.properties with spring.jdbc.getParameterType.ignore=true
  8. spring-projects-issues commented on Nov 16, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Alright, let's turn this into a documentation task then, putting specific notes for Oracle 12c into our reference documentation.

  9. spring-projects-issues commented on Nov 18, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    BTW, I've created #20763 inspired by your source code example (and a similar case in our reference documentation). Such manual collection adaptation shouldn't be necessary. I've added overloaded methods to SqlParameterSourceUtils, allowing for the following concise code:

    public int[] saveBatchOutputs(final String updateSql, final List<Map<String, Object>> batchValuesList) {
        return namedParameterJdbcTemplate.batchUpdate(updateSql, SqlParameterSourceUtils.createBatch(batchValuesList));
    }
    
  10. spring-projects-issues commented on Nov 19, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Adam Sojka commented

    Juergen, Thank you very much for resolving the issue.

  11. added
    in: data
    type: task
    on Jan 11, 2019
  12. added this to the 5.0.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: task

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions