Shardingsphere: sharding is not support LocalDateTime type field

Created on 10 Oct 2019  ·  9Comments  ·  Source: apache/shardingsphere

Bug Report

InvalidDataAccessApiUsageException: Error attempting to get column 'create_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException: getObject with type
; getObject with type; nested exception is java.sql.SQLFeatureNotSupportedException.

getObject with type
at org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationResultSet.getObject(AbstractUnsupportedOperationResultSet.java:223) ~[sharding-jdbc-core-4.0.0-RC2.jar:4.0.0-RC2]
at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:38) ~[mybatis-3.5.1.jar:3.5.1]
at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:28) ~[mybatis-3.5.1.jar:3.5.1]
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:81) ~[mybatis-3.5.1.jar:3.5.1]

invalid

Most helpful comment

Shardingjdbc is based on JDK version 1.7 by default, so there is no localDate feature. If you want to solve this problem, please upgrade the source code to jdk1.8, and compatible with this type, you can refer to my repository's 4.0.0-rc2-1.8 branch.

https://github.com/lonyee1989/incubator-shardingsphere/tree/4.0.0-RC2-1.8

在 2020年4月25日,14:28,yc825106632 notifications@github.com 写道:



在4.0.1中依然有这个问题,而且也是不支持LocalDateTime,在程序处理之后,竟然把日期搞成数组了
[image]https://user-images.githubusercontent.com/21304095/80272958-cf8b8b00-8700-11ea-8717-b2fbc952a964.png

[image]https://user-images.githubusercontent.com/21304095/80272975-f9dd4880-8700-11ea-87ec-63984c05dc6b.png


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHubhttps://github.com/apache/shardingsphere/issues/3203#issuecomment-619329895, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACK4JQ5RJ7A4AWMASLKMB7TROJ7JFANCNFSM4I7HQBUQ.

All 9 comments

@terrymanu shardingsphere defaulf jdk version is 1.7

I've extended this feature on fork and upgraded the JDK to 1.8 for functionality.

4.0.0-RC2-1.8
https://github.com/lonyee1989/incubator-shardingsphere/tree/4.0.0-RC2-1.8

_Mybatis 5+ is mainly supported_

The implementation code

  1. package org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset;
    /**
     * Convert value via expected class type.
     * 
     * @param value original value
     * @param convertType expected class type
     * @return converted value
     */
    public static Object convertValue(final Object value, final Class<?> convertType) {
        if (null == value) {
            return convertNullValue(convertType);
        } 
        if (value.getClass() == convertType) {
            return value;
        }
        if (LocalDateTime.class.equals(convertType)) {
            return convertLocalDateTimeValue(value, convertType);
        }
        if (LocalDate.class.equals(convertType)) {
            return convertLocalDateValue(value, convertType);
        }
        if (LocalTime.class.equals(convertType)) {
            return convertLocalTimeValue(value, convertType);
        }


        if (value instanceof Number) {
            return convertNumberValue(value, convertType);
        }
        if (value instanceof Date) {
            return convertDateValue(value, convertType);
        }
        if (value instanceof byte[]) {
            return convertByteArrayValue(value, convertType);
        }
        if (String.class.equals(convertType)) {
            return value.toString();
        } else {
            return value;
        }
    }

  ......

  private static Object convertLocalDateTimeValue(final Object value, final Class<?> convertType) {
        Timestamp timestamp = (Timestamp) value;
        return timestamp.toLocalDateTime();
    }

    private static Object convertLocalDateValue(final Object value, final Class<?> convertType) {
        Timestamp timestamp = (Timestamp) value;
        return timestamp.toLocalDateTime().toLocalDate();
    }

    private static Object convertLocalTimeValue(final Object value, final Class<?> convertType) {
        Timestamp timestamp = (Timestamp) value;
        return timestamp.toLocalDateTime().toLocalTime();
    }

  1. package org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset;
    @Override
    public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException {
        if (LocalDateTime.class.equals(type) || LocalDate.class.equals(type) || LocalTime.class.equals(type)) {
            return (T) ResultSetUtil.convertValue(mergeResultSet.getValue(columnIndex, Timestamp.class), type);
        }
        throw new SQLFeatureNotSupportedException("getObject with type");
    }

    @Override
    public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException {
        if (LocalDateTime.class.equals(type) || LocalDate.class.equals(type) || LocalTime.class.equals(type)) {
            return (T) ResultSetUtil.convertValue(mergeResultSet.getValue(columnLabel, Timestamp.class), type);
        }
        throw new SQLFeatureNotSupportedException("getObject with type");
    }

  1. package org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset;
    @Override
    public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException {
        if (LocalDateTime.class.equals(type) || LocalDate.class.equals(type) || LocalTime.class.equals(type)) {
            return (T) ResultSetUtil.convertValue(resultSet.getValue(columnIndex, Timestamp.class), type);
        }
        throw new SQLFeatureNotSupportedException("getObject with type");
    }

    @Override
    public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException {
        if (LocalDateTime.class.equals(type) || LocalDate.class.equals(type) || LocalTime.class.equals(type)) {
            return (T) ResultSetUtil.convertValue(resultSet.getValue(columnLabel, Timestamp.class), type);
        }
        throw new SQLFeatureNotSupportedException("getObject with type");
    }

  1. package org.apache.shardingsphere.shardingjdbc.jdbc.unsupported;
    @Override
    public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException {
        throw new SQLFeatureNotSupportedException("getObject with type");
    }

    @Override
    public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException {
        throw new SQLFeatureNotSupportedException("getObject with type");
    }

What is the reason of close the issue?

@terrymanu Shardingsphere is now implemented based on jdk1.7, but LocalDateTime is jdk1.8+. I have implemented mybatis and LocalDateTime by using the extension of getObject().

In version 4.0.1, the support for localdatetime is not available. How to deal with this problem with version 4.0.1
image

image

在4.0.1中依然有这个问题,而且也是不支持LocalDateTime,在程序处理之后,竟然把日期搞成数组了
image

image

Shardingjdbc is based on JDK version 1.7 by default, so there is no localDate feature. If you want to solve this problem, please upgrade the source code to jdk1.8, and compatible with this type, you can refer to my repository's 4.0.0-rc2-1.8 branch.

https://github.com/lonyee1989/incubator-shardingsphere/tree/4.0.0-RC2-1.8

Shardingjdbc is based on JDK version 1.7 by default, so there is no localDate feature. If you want to solve this problem, please upgrade the source code to jdk1.8, and compatible with this type, you can refer to my repository's 4.0.0-rc2-1.8 branch.

https://github.com/lonyee1989/incubator-shardingsphere/tree/4.0.0-RC2-1.8

在 2020年4月25日,14:28,yc825106632 notifications@github.com 写道:



在4.0.1中依然有这个问题,而且也是不支持LocalDateTime,在程序处理之后,竟然把日期搞成数组了
[image]https://user-images.githubusercontent.com/21304095/80272958-cf8b8b00-8700-11ea-8717-b2fbc952a964.png

[image]https://user-images.githubusercontent.com/21304095/80272975-f9dd4880-8700-11ea-87ec-63984c05dc6b.png


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHubhttps://github.com/apache/shardingsphere/issues/3203#issuecomment-619329895, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACK4JQ5RJ7A4AWMASLKMB7TROJ7JFANCNFSM4I7HQBUQ.

any update for the LocalDateTime exception here all guys met?

Arrays are spring's problem, just turn around.

Was this page helpful?
0 / 5 - 0 ratings