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

Regression in handling of String passed as Types.OTHER to JdbcTemplate [SPR-12890] #17488

Closed
spring-projects-issues opened this issue Apr 4, 2015 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 4, 2015

Alex Panchenko opened SPR-12890 and commented

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?


Affects: 4.1 GA

Issue Links:

Referenced from: commits 050e581, e95a7a4

@spring-projects-issues
Copy link
Collaborator Author

Alex Panchenko commented

The simplified statement looks like this:

jdbcTemplate.queryForObject("insert into foo (id, json_field) values (nextval(foo_seq),?) returning id", 
new Object[]{jsonValue},
new int[]{Types.OTHER},
Long.class);

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 16, 2015

Juergen Hoeller commented

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.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

2 participants