Skip to content

JDBCType BIT for boolean classes #1800

Open
@kurtymckurt

Description

@kurtymckurt

The mapping of Java classes to JDBCType is currently static.
We should provide a way to customize that mapping, possibly via the @Column annotation and allow for a customization by different Dialect implementations.

Original issue, as raised by @kurtymckurt

I'm bringing this as curiosity because i'm not entirely sure if its an issue. I was recently using a JDBC driver for a proprietary system and their driver does not support the BIT JDBC type. Therefore, when using boolean fields, it would fail. It made me look into it and noticed that your mappings of Java classes to JDBC Type had BIT for boolean/Boolean as you can see here:

However, the Spring framework JDBC core library seems to map Boolean/boolean to Types.BOOLEAN. You can see here:
https://github.com/spring-projects/spring-framework/blob/main/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java#L92

One obvious solution is to ask the proprietary company to support BIT type. I am curious if the BIT for boolean/Boolean deviation was purposeful. As a work around, i'm currently using reflection to remap the types as its a small service and the impact of this change seems rather low. Am I missing any other impact from doing this?

    Class<?> clazz = JdbcUtil.class;
    Field field = clazz.getDeclaredField("sqlTypeMappings");
    field.setAccessible(true);
    Map<Class<?>, SQLType> map = (Map<Class<?>, SQLType>) field.get(null);
    map.put(Boolean.class, JDBCType.BOOLEAN);
    map.put(boolean.class, JDBCType.BOOLEAN);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions