While reading result set into java records mapping types are resolved incorrectly
Opened this issue · 1 comments
avasiliuk commented
When querying data I get this exception for incorrect enum value.
Here are my result mappings:
And here is the problem - constructor argument types are resolved by index without care of nested objects:
org.mybatis.spring.MyBatisSystemException:
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'symbol' from result set. Cause: java.lang.IllegalArgumentException: No enum constant org.v.backend.model.internal.Interval.BTCUSDT
### The error may exist in org/v/backend/repository/clickhouse/CandleClickhouseRepository.xml
### The error may involve org.v.backend.repository.clickhouse.CandleClickhouseRepository.selectCandles
### The error occurred while handling results
### SQL: with (select toStartOfInterval(c.timestamp, interval 5 minute) from candles_m1 c where c.exchange = ? and c.symbol = ? and c.symbol_type = ? order by c.timestamp desc limit 1) as last_period select any(c.exchange) as exchange, any(c.symbol) as symbol, toStartOfInterval(c.timestamp, interval 5 minute) as timestamp, ? as interval, any(symbol_type) as symbol_type, argMin(c.open, c.timestamp) as open, max(c.high) as high, min(c.low) as low, argMax(c.close, c.timestamp) as close, last_period != toStartOfInterval(c.timestamp, interval 5 minute) as closed from candles_m1 c where c.exchange = ? and c.symbol = ? and c.symbol_type = ? group by (c.exchange, c.symbol_type, c.symbol, timestamp) order by timestamp desc;
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'symbol' from result set. Cause: java.lang.IllegalArgumentException: No enum constant org.v.backend.model.internal.Interval.BTCUSDT
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:99) ~[mybatis-spring-3.0.4.jar:3.0.4]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:347) ~[mybatis-spring-3.0.4.jar:3.0.4]
at jdk.proxy2/jdk.proxy2.$Proxy96.selectOne(Unknown Source) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:154) ~[mybatis-spring-3.0.4.jar:3.0.4]
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:141) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86) ~[mybatis-3.5.17.jar:3.5.17]
at jdk.proxy4/jdk.proxy4.$Proxy98.selectCandles(Unknown Source) ~[na:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355) ~[spring-aop-6.1.12.jar:6.1.12]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.1.12.jar:6.1.12]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-6.1.12.jar:6.1.12]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:379) ~[spring-tx-6.1.12.jar:6.1.12]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-6.1.12.jar:6.1.12]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.12.jar:6.1.12]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223) ~[spring-aop-6.1.12.jar:6.1.12]
at jdk.proxy4/jdk.proxy4.$Proxy99.selectCandles(Unknown Source) ~[na:na]
at org.v.backend.service.CandleService.getCandles(CandleService.java:33) ~[main/:na]
at org.v.backend.BackendApplication.lambda$commandLineRunner2$1(BackendApplication.java:76) ~[main/:na]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-6.1.12.jar:6.1.12]
at org.v.backend.BackendApplication.lambda$commandLineRunner2$2(BackendApplication.java:75) ~[main/:na]
at org.springframework.boot.SpringApplication.lambda$callRunner$5(SpringApplication.java:790) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.12.jar:6.1.12]
at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.12.jar:6.1.12]
at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88) ~[spring-core-6.1.12.jar:6.1.12]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:789) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774) ~[spring-boot-3.3.3.jar:3.3.3]
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:na]
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:557) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) ~[na:na]
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:na]
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) ~[na:na]
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:611) ~[na:na]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:342) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) ~[spring-boot-3.3.3.jar:3.3.3]
at org.v.backend.BackendApplication.main(BackendApplication.java:55) ~[main/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.3.3.jar:3.3.3]
Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'symbol' from result set. Cause: java.lang.IllegalArgumentException: No enum constant org.v.backend.model.internal.Interval.BTCUSDT
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:88) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyColumnOrderBasedConstructorAutomapping(DefaultResultSetHandler.java:790) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyConstructorAutomapping(DefaultResultSetHandler.java:776) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:727) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:689) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:659) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:411) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:366) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:337) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:310) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:202) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:66) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:80) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.BatchExecutor.doQuery(BatchExecutor.java:94) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:336) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:158) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:110) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:90) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:154) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:142) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:75) ~[mybatis-3.5.17.jar:3.5.17]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:333) ~[mybatis-spring-3.0.4.jar:3.0.4]
... 42 common frames omitted
Caused by: java.lang.IllegalArgumentException: No enum constant org.v.backend.model.internal.Interval.BTCUSDT
at java.base/java.lang.Enum.valueOf(Enum.java:293) ~[na:na]
at org.apache.ibatis.type.EnumTypeHandler.getNullableResult(EnumTypeHandler.java:49) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.type.EnumTypeHandler.getNullableResult(EnumTypeHandler.java:26) ~[mybatis-3.5.17.jar:3.5.17]
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:86) ~[mybatis-3.5.17.jar:3.5.17]
... 66 common frames omitted
harawata commented
Hello @avasiliuk ,
Please create a small repro project and share it on your GitHub repo.
Here are some project templates and examples.
https://github.com/harawata/mybatis-issues
Thank you!