You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression in handling of String passed as Types.OTHER to JdbcTemplate [SPR-12890] #17488
For PostgreSQL if columns are defined as JSON or XML, then String values should be passed via setObject. We are doing that via JdbcTemplate.
Now that code throws an exception after the change 759f430 from #13215 which always passes String via setString().
As I commented on the commit: IMHO JdbcTemplate should not be too smart - if I pass String as OTHER - it should reach the driver as is. OTHER is documented as "indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject" So, probably some other place using OTHER is just not doing that correctly?
jdbcTemplate.queryForObject("insert into foo (id, json_field) values (nextval(foo_seq),?) returning id",
new Object[]{jsonValue},
new int[]{Types.OTHER},
Long.class);
The problem behind #13215 is that the Oracle driver returns Types.OTHER for an NVARCHAR2 column in its DatabaseMetaData but then doesn't accept a String value through setObject, just through setString... Arguably the Oracle driver isn't fully JDBC-compliant there. Maybe we'll need to a check for Oracle there and only use the specific setters for Types.OTHER in that case.
A search through Oracle's forums reveals that there are plenty of cases where Oracle exposes Types.OTHER in its metadata but doesn't accept it on setObject / setNull. As a consequence, I've introduced an explicit check that only uses setString etc for Types.OTHER in case of Oracle. I've left the null handling code path as-is since it doesn't seem to hurt to check the metadata parameter type for Types.OTHER on any database.
Activity
spring-projects-issues commentedon Apr 4, 2015
Alex Panchenko commented
The simplified statement looks like this:
spring-projects-issues commentedon Apr 16, 2015
Juergen Hoeller commented
The problem behind #13215 is that the Oracle driver returns
Types.OTHERfor an NVARCHAR2 column in itsDatabaseMetaDatabut then doesn't accept a String value throughsetObject, just throughsetString... Arguably the Oracle driver isn't fully JDBC-compliant there. Maybe we'll need to a check for Oracle there and only use the specific setters forTypes.OTHERin that case.Juergen
spring-projects-issues commentedon Apr 16, 2015
Juergen Hoeller commented
A search through Oracle's forums reveals that there are plenty of cases where Oracle exposes
Types.OTHERin its metadata but doesn't accept it onsetObject/setNull. As a consequence, I've introduced an explicit check that only usessetStringetc forTypes.OTHERin case of Oracle. I've left thenullhandling code path as-is since it doesn't seem to hurt to check the metadata parameter type forTypes.OTHERon any database.Juergen