Skip to content

Java boolean is not handled correctly when used with Oracle JDBC driver [SPR-14116] #18688

Closed

Description

@spring-projects-issues

Igor Voshkulat opened SPR-14116 and commented

Database field is defined as NUMBER(1,0).
Model object with a boolean field is mapped to parameters via SqlParameterSourceUtil.createBatch().

In version 3.2.2.RELEASE StatementCreationUtils.javaTypeToSqlTypeMap had no mapping for java boolean (more precisely it was commented out) and was working fine. This resulted in StatementCreationUtils.setValue() to execute ps.setObject(paramIndex, inValue).

After boolean mapping was uncommented ps.setObject(paramIndex, inValue, sqlType) is used.

Oracle doesn't have proper matching boolean type, however driver is smart enough to do automatic conversion from boolean to NUMBER.

Therefore following statements are valid:
ps.setObject(1, true);
ps.setBoolean(1, true);
ps.setObject(1, true, Types.NUMERIC); //very narrow-minded, works for this particular case but not generic enough

What is currently done:
ps.setObject(1, true, Types.BOOLEAN);

Which fails with invalid column type 17004.


Affects: 4.2.5

Issue Links:

Referenced from: commits 797f5db, 6b0f26c

Activity

  1. spring-projects-issues commented on Apr 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Thanks for raising this! We're explicitly calling PreparedStatement.setBoolean for Types.BOOLEAN now, which seems to be a sensible processing path in any case.

  2. added
    type: bug
    in: data
    on Jan 11, 2019
  3. added this to the 4.2.6 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: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions