I'm working on a springboot app in which mybatis is calling a DB2 stored procedure and this stored procedure is returning 2 result sets: and for each result set I defined a model(Fruit.java and Animal.java)
result set #1
| ID | NAME | QTY |
|---|---|---|
| 1 | Apple | 2 |
| 2 | Orange | 3 |
| 3 | banana | 5 |
result set #2
| TYPE | NUM | LOC |
|---|---|---|
| monkey | 2000 | London |
| dog | 3000 | New York |
| cat | 8000 | LA |
in MyMapper.java, what should my resultType be?
I have tried:
@Select(Value = "{call ....})
@Options(StatementType = StatementType.CALLABLE)
@Results({
@Result(property="id", column="ID",
@Result(property="name", column="NAME",
@Result(property="qty", column="QTY" })
List<Fruit> getFruits(Map<String, String> params);
@Select(Value = "{call ....})
@Options(StatementType = StatementType.CALLABLE)
@Results({
@Result(property="type", column="TYPE",
@Result(property="num", column="NUM",
@Result(property="loc", column="LOC"
})
List<Animal> getAnimals(Map<String, String> params);
which didn't work, I did get result set #1 ok this way but not getting result set #2 (all fields from result set#2 came back null) .
I also tried:
@Select(Value = "{call ....})
@Options(StatementType = StatementType.CALLABLE)
List<?> getResultSets(Map<String, String> params);
and:
@Select(Value = "{call ....})
@Options(StatementType = StatementType.CALLABLE)
List<List<?>> getResultSets(Map<String, String> params);
For both I got "java.lang.UnsupportedOperationException":
Caused by: java.lang.UnsupportedOperationException
at org.apache.ibatis.reflection.wrapper.CollectionWrapper.findProperty(CollectionWrapper.java:42)
at org.apache.ibatis.reflection.MetaObject.findProperty(MetaObject.java:76)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.applyAutomaticMappings(FastResultSetHandler.java:342)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.getRowValue(FastResultSetHandler.java:267)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleRowValues(FastResultSetHandler.java:216)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSet(FastResultSetHandler.java:188)
at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:154)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)
at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:54)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
Google says it's because I should use a concrete type instead of generics. But the result sets are of different types: List of Fruit and List of Animal , what do I do?
I'm using all annotations and no xml for mybatis. in pom.xml I'm using mybatis-spring-boot-starter if that helps.
I have been stuck on this forever. Thanks.