使用mybatis-plus连接达梦数据库,枚举类型无法读取
枚举类:
实体:
数据库字段:
mybatis-plus枚举包配置:
调用查询方法:
List<QualityRuleTemplate> qualityRuleTemplates = ruleTemplateService.list(new QueryWrapper<QualityRuleTemplate>().lambda()
.eq(QualityRuleTemplate::getRuleType, QualityRuleTypeEnum.DATASOURCE));
报错:
Caused by: dm.jdbc.driver.DMException: 不支持的接口或功能
at dm.jdbc.driver.DBError.throwException(DBError.java:710) ~[DmJdbcDriver18-8.1.1.193.jar:- 8.1.1.193 - Production]
at dm.jdbc.driver.DmdbResultSet.do_getObject(DmdbResultSet.java:1972) ~[DmJdbcDriver18-8.1.1.193.jar:- 8.1.1.193 - Production]
at dm.jdbc.driver.DmdbResultSet.do_getObject(DmdbResultSet.java:1978) ~[DmJdbcDriver18-8.1.1.193.jar:- 8.1.1.193 - Production]
at dm.jdbc.driver.DmdbResultSet.getObject(DmdbResultSet.java:5335) ~[DmJdbcDriver18-8.1.1.193.jar:- 8.1.1.193 - Production]
at com.alibaba.druid.filter.FilterChainImpl.resultSet_getObject(FilterChainImpl.java:1395) ~[druid-1.2.18.jar:?]
at com.alibaba.druid.filter.FilterAdapter.resultSet_getObject(FilterAdapter.java:1712) ~[druid-1.2.18.jar:?]
at com.alibaba.druid.filter.FilterChainImpl.resultSet_getObject(FilterChainImpl.java:1391) ~[druid-1.2.18.jar:?]
at com.alibaba.druid.filter.stat.StatFilter.resultSet_getObject(StatFilter.java:878) ~[druid-1.2.18.jar:?]
at com.alibaba.druid.filter.FilterChainImpl.resultSet_getObject(FilterChainImpl.java:1391) ~[druid-1.2.18.jar:?]
at com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl.getObject(ResultSetProxyImpl.java:1546) ~[druid-1.2.18.jar:?]
at com.alibaba.druid.pool.DruidPooledResultSet.getObject(DruidPooledResultSet.java:1765) ~[druid-1.2.18.jar:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69) ~[mybatis-3.5.7.jar:3.5.7]
at com.sun.proxy.$Proxy489.getObject(Unknown Source) ~[?:?]
at com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler.getNullableResult(MybatisEnumTypeHandler.java:118) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
at com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler.getNullableResult(MybatisEnumTypeHandler.java:49) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:561) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:403) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:355) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:329) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:302) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:195) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.7.jar:3.5.7]
at jdk.internal.reflect.GeneratedMethodAccessor44.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:64) ~[mybatis-3.5.7.jar:3.5.7]
at com.sun.proxy.$Proxy486.query(Unknown Source) ~[?:?]
at jdk.internal.reflect.GeneratedMethodAccessor44.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:64) ~[mybatis-3.5.7.jar:3.5.7]
at com.sun.proxy.$Proxy486.query(Unknown Source) ~[?:?]
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.7.jar:3.5.7]
at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81) ~[mybatis-plus-extension-3.4.3.4.jar:3.4.3.4]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) ~[mybatis-3.5.7.jar:3.5.7]
at com.sun.proxy.$Proxy484.query(Unknown Source) ~[?:?]
at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81) ~[mybatis-plus-extension-3.4.3.4.jar:3.4.3.4]
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) ~[mybatis-3.5.7.jar:3.5.7]
at com.sun.proxy.$Proxy484.query(Unknown Source) ~[?:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) ~[mybatis-3.5.7.jar:3.5.7]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.7.jar:3.5.7]
at jdk.internal.reflect.GeneratedMethodAccessor65.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
at com.sun.proxy.$Proxy143.selectList(Unknown Source) ~[?:?]
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
at com.sun.proxy.$Proxy259.selectList(Unknown Source) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:220) ~[spring-aop-5.3.27.jar:5.3.27]
at com.sun.proxy.$Proxy260.selectList(Unknown Source) ~[?:?]
at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:289) ~[mybatis-plus-extension-3.4.3.4.jar:3.4.3.4]
at com.baomidou.mybatisplus.extension.service.IService$$FastClassBySpringCGLIB$$f8525d18.invoke(<generated>) ~[mybatis-plus-extension-3.4.3.4.jar:3.4.3.4]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) ~[spring-aop-5.3.27.jar:5.3.27]
at cn.ac.iscas.dmo.rest.service.quality.impl.QualityRuleTemplateServiceImpl$$EnhancerBySpringCGLIB$$171f9f98.list(<generated>) ~[main/:?]
at cn.ac.iscas.dmo.rest.service.quality.impl.QualityRuleServiceImpl.getData(QualityRuleServiceImpl.java:72) ~[main/:?]
at cn.ac.iscas.dmo.rest.service.quality.impl.QualityRuleServiceImpl$$FastClassBySpringCGLIB$$801bb2da.invoke(<generated>) ~[main/:?]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) ~[spring-aop-5.3.27.jar:5.3.27]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) ~[spring-aop-5.3.27.jar:5.3.27]
at cn.ac.iscas.dmo.rest.service.quality.impl.QualityRuleServiceImpl$$EnhancerBySpringCGLIB$$dd27b566.getData(<generated>) ~[main/:?]
at cn.ac.iscas.dmo.rest.controller.quality.QualityRuleController.getDatasourceData(QualityRuleController.java:50) ~[main/:?]
查看mybatis-plus对枚举处理的handler:MybatisEnumTypeHandler
@Override
public E getNullableResult(ResultSet rs, String columnName) throws SQLException {
Object value = rs.getObject(columnName, this.propertyType);
if (null == value && rs.wasNull()) {
return null;
}
return this.valueOf(value);
}
调用了rs.getObject(columnName, this.propertyType)方法,此时this.propertyType是String
继续一直跟踪代码,发现最终调用了最终调用DmdbResultSet类中的方法:public Object do_getObject(int var1, Class var2)
public Object do_getObject(int var1, Class var2) {
DmdbTimestamp var3;
if (var2 == LocalDateTime.class) {
var3 = this.getTIMESTAMP(var1);
return var3 == null ? null : LocalDateTime.of(var3.dt[0], var3.dt[1], var3.dt[2], var3.dt[3], var3.dt[4], var3.dt[5], var3.dt[6] * 1000);
} else if (var2 == LocalDate.class) {
var3 = this.getTIMESTAMP(var1);
return var3 == null ? null : LocalDate.of(var3.dt[0], var3.dt[1], var3.dt[2]);
} else if (var2 == LocalTime.class) {
var3 = this.getTIMESTAMP(var1);
return var3 == null ? null : LocalTime.of(var3.dt[3], var3.dt[4], var3.dt[5], var3.dt[6] * 1000);
} else if (var2 == ZonedDateTime.class) {
var3 = this.getTIMESTAMP(var1);
return var3 == null ? null : ZonedDateTime.of(var3.dt[0], var3.dt[1], var3.dt[2], var3.dt[3], var3.dt[4], var3.dt[5], var3.dt[6] * 1000, ZoneOffset.ofTotalSeconds(var3.dt[7] != Integer.MIN_VALUE ? var3.dt[7] * 60 : this.connection.localTimezone * 60));
} else if (var2 == OffsetDateTime.class) {
var3 = this.getTIMESTAMP(var1);
return var3 == null ? null : OffsetDateTime.of(var3.dt[0], var3.dt[1], var3.dt[2], var3.dt[3], var3.dt[4], var3.dt[5], var3.dt[6] * 1000, ZoneOffset.ofTotalSeconds(var3.dt[7] != Integer.MIN_VALUE ? var3.dt[7] * 60 : this.connection.localTimezone * 60));
} else if (var2 == OffsetTime.class) {
var3 = this.getTIMESTAMP(var1);
return var3 == null ? null : OffsetTime.of(var3.dt[3], var3.dt[4], var3.dt[5], var3.dt[6] * 1000, ZoneOffset.ofTotalSeconds(var3.dt[7] != Integer.MIN_VALUE ? var3.dt[7] * 60 : this.connection.localTimezone * 60));
} else {
DBError.ECJDBC_UNSUPPORTED_INTERFACE.throwException(new String[0]);
return null;
}
}
找到了问题所在,没有对String进行处理
这个类在达梦的驱动包里,我之前用的8.1.1.193,尝试更新版本为8.1.3.62
新的驱动中的处理
public <T> T do_getObject(int columnIndex, Class<T> type) throws SQLException {
if (type == String.class) {
return this.do_getString(columnIndex);
} else if (type == Clob.class) {
return this.do_getClob(columnIndex);
} else if (type == NClob.class) {
return this.do_getNClob(columnIndex);
} else if (type == Boolean.class) {
return this.do_getBoolean(columnIndex);
} else if (type == Long.class) {
return this.do_getLong(columnIndex);
} else if (type == Integer.class) {
return this.do_getInt(columnIndex);
} else if (type == Short.class) {
return this.do_getShort(columnIndex);
} else if (type == BigDecimal.class) {
return this.do_getBigDecimal(columnIndex);
} else if (type == Float.class) {
return this.do_getFloat(columnIndex);
} else if (type == Double.class) {
return this.do_getDouble(columnIndex);
} else if (type == Byte.class) {
return this.do_getByte(columnIndex);
} else if (type == byte[].class) {
return this.do_getBytes(columnIndex);
} else if (type == Blob.class) {
return this.do_getBlob(columnIndex);
} else if (type == Date.class) {
return this.do_getDate(columnIndex);
} else if (type == Time.class) {
return this.do_getTime(columnIndex);
} else if (type == Timestamp.class) {
return this.do_getTimestamp(columnIndex);
} else if (type == java.util.Date.class) {
Timestamp t = this.do_getTimestamp(columnIndex);
return t == null ? null : new java.util.Date(t.getTime());
} else {
DmdbTimestamp t;
if (type == LocalDateTime.class) {
t = this.getTIMESTAMP(columnIndex);
return t == null ? null : LocalDateTime.of(t.dt[0], t.dt[1], t.dt[2], t.dt[3], t.dt[4], t.dt[5], t.dt[6]);
} else if (type == LocalDate.class) {
t = this.getTIMESTAMP(columnIndex);
return t == null ? null : LocalDate.of(t.dt[0], t.dt[1], t.dt[2]);
} else if (type == LocalTime.class) {
t = this.getTIMESTAMP(columnIndex);
return t == null ? null : LocalTime.of(t.dt[3], t.dt[4], t.dt[5], t.dt[6]);
} else if (type == ZonedDateTime.class) {
t = this.getTIMESTAMP(columnIndex);
return t == null ? null : ZonedDateTime.of(t.dt[0], t.dt[1], t.dt[2], t.dt[3], t.dt[4], t.dt[5], t.dt[6], ZoneOffset.ofTotalSeconds(t.dt[7] != Integer.MIN_VALUE ? t.dt[7] * 60 : this.connection.localTimezone * 60));
} else if (type == OffsetDateTime.class) {
t = this.getTIMESTAMP(columnIndex);
return t == null ? null : OffsetDateTime.of(t.dt[0], t.dt[1], t.dt[2], t.dt[3], t.dt[4], t.dt[5], t.dt[6], ZoneOffset.ofTotalSeconds(t.dt[7] != Integer.MIN_VALUE ? t.dt[7] * 60 : this.connection.localTimezone * 60));
} else if (type == OffsetTime.class) {
t = this.getTIMESTAMP(columnIndex);
return t == null ? null : OffsetTime.of(t.dt[3], t.dt[4], t.dt[5], t.dt[6], ZoneOffset.ofTotalSeconds(t.dt[7] != Integer.MIN_VALUE ? t.dt[7] * 60 : this.connection.localTimezone * 60));
} else if (type == Array.class) {
return this.do_getArray(columnIndex);
} else if (type == Struct.class) {
return this.do_getStruct(columnIndex);
} else if (type == Ref.class) {
return this.do_getRef(columnIndex);
} else if (type == SQLXML.class) {
return this.do_getSQLXML(columnIndex);
} else if (type == URL.class) {
return this.do_getURL(columnIndex);
} else if (type == RowId.class) {
return this.do_getRowId(columnIndex);
} else {
DBError.ECJDBC_UNSUPPORTED_TYPE.throwz(new Object[0]);
return null;
}
}
}
问题至此解决了