From 8d743d9946cc841c269fc86ea74c79e7f5640a28 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 5 Sep 2020 13:55:26 +0200 Subject: [PATCH] Revise documentation notes on getParameterType performance issues See gh-25679 --- .../jdbc/core/StatementCreatorUtils.java | 13 ++++++------- src/docs/asciidoc/data-access.adoc | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java index 8d12b1fbd3..e3562f3eed 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java @@ -66,12 +66,11 @@ public abstract class StatementCreatorUtils { * completely, i.e. to never even attempt to retrieve {@link PreparedStatement#getParameterMetaData()} * for {@link StatementCreatorUtils#setNull} calls. *

The default is "false", trying {@code getParameterType} calls first and falling back to - * {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on well-known - * behavior of common databases. Spring records JDBC drivers with non-working {@code getParameterType} - * implementations and won't attempt to call that method for that driver again, always falling back. - *

Consider switching this flag to "true" if you experience misbehavior at runtime, e.g. with - * a connection pool setting back the {@link PreparedStatement} instance in case of an exception - * thrown from {@code getParameterType} (as reported on JBoss AS 7). + * {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on + * well-known behavior of common databases. + *

Consider switching this flag to "true" if you experience misbehavior at runtime, + * e.g. with connection pool issues in case of an exception thrown from {@code getParameterType} + * (as reported on JBoss AS 7) or in case of performance problems (as reported on PostgreSQL). */ public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore"; @@ -266,7 +265,7 @@ public abstract class StatementCreatorUtils { } else if (databaseProductName.startsWith("DB2") || jdbcDriverName.startsWith("jConnect") || - jdbcDriverName.startsWith("SQLServer")|| + jdbcDriverName.startsWith("SQLServer") || jdbcDriverName.startsWith("Apache Derby")) { sqlTypeToUse = Types.VARCHAR; } diff --git a/src/docs/asciidoc/data-access.adoc b/src/docs/asciidoc/data-access.adoc index a42878fcdf..33ce8c0161 100644 --- a/src/docs/asciidoc/data-access.adoc +++ b/src/docs/asciidoc/data-access.adoc @@ -3379,7 +3379,7 @@ While this usually works well, there is a potential for issues, e.g. with Map-co case which may be expensive with your JDBC driver. Please make sure to use a recent driver version, and consider setting the "spring.jdbc.getParameterType.ignore" property to "true" (as a JVM system property or in a `spring.properties` file in the root of your classpath) -if you encounter a performance issue, e.g. as reported on Oracle 12c (SPR-16139). +if you encounter a performance issue (as reported on Oracle 12c, JBoss and PostgreSQL). Alternatively, simply consider specifying the corresponding JDBC types explicitly: either via a 'BatchPreparedStatementSetter' as shown above, or via an explicit type