Upgrade 3.2.8 to 3.4.1 get NPE on result with collection that uses composite key

26 views
Skip to first unread message

Crater Void

unread,
Aug 9, 2016, 1:17:33 PM8/9/16
to mybatis-user
I'm trying to upgrade from mybatis 3.2.8 to 3.4.1.  Getting null pointer exception on a result containing a collection that uses composite keys. The code below worked with 3.2.8.  It also does not work with mybatis 3.3.0 or 3.4.1.

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.NullPointerException
### The error may exist in Locations.xml
### The error may involve Mapper.getLocationsWhere
### The error occurred while handling results
### SQL: SELECT DISTINCT A.TTYPE, A.LOCATION, A.YYEAR, A.CLASST, A.SEQU, A.DTE, A.CASETYP, C.CNT, C.CID, C.CSEQ, C.DESCRPT, C.DESCR, C.DESCRT, C.DESCRS, C.DESCRSTS  FROM ADESCRSTBL A        
INNER JOIN CABSTBL C ON A.TTYPE=C.TTYPE AND A.LOCATION=C.LOCATION AND A.YYEAR=C.YYEAR AND A.CLASST=C.CLASST AND A.SEQU=C.SEQU
          WHERE A.LOCATION=12
### Cause: java.lang.NullPointerException
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
    at com.sun.proxy.$Proxy0.getLocationsSearch(Unknown Source)
    at rest.Test.main(Test.java:44)
Caused by: java.lang.NullPointerException
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:411)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:384)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:789)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:757)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:271)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:246)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:160)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
    ... 6 more


XML file:   
   
    <resultMap id="resultLocations" type="Location">
       <result property="ttype" jdbcType="VARCHAR" column="TTYPE" />
        <result property="location" jdbcType="NUMERIC"  column="LOCATION" />
        <result property="yyear" column="YYEAR" />
        <result property="classt" jdbcType="VARCHAR" column="CLASST" />
        <result property="sequ" jdbcType="NUMERIC" column="SEQU" />  
        <result property="dte" jdbcType="NUMERIC" column="DTE" />  
        <result property="casetyp" jdbcType="VARCHAR" column="CASETYP" />
        <collection property="places" column="{TTYPE=TTYPE,LOCATION=LOCATION,YYEAR=YYEAR,CLASST=CLASST,SEQU=SEQU,DTE=DTE,CASETYP=CASETYP}" javaType="ArrayList" ofType="Place"> 
            <result property="cnt" jdbcType="NUMERIC" column="CNT"/>
            <result property="cid" jdbcType="NUMERIC" column="CID"/>
            <result property="cseq" jdbcType="NUMERIC" column="CSEQ"/>
            <result property="descrpt" jdbcType="VARCHAR" column="DESCRPT"/>
            <result property="descr" jdbcType="VARCHAR"  column="DESCR"/>
            <result property="descrt" jdbcType="VARCHAR" column="DESCRT"/>
            <result property="descrs" jdbcType="NUMERIC" column="DESCRS" />
            <result property="descrsts" jdbcType="VARCHAR" column="DESCRSTS"/>
        </collection>
    </resultMap>
   
Configuration:

    <settings>
        <setting name="jdbcTypeForNull" value="NULL"/>
        <setting name="callSettersOnNulls" value="true"/>
    </settings>

Any ideas?
Thanks much

Iwao AVE!

unread,
Aug 9, 2016, 1:50:14 PM8/9/16
to mybatis-user
Hi,

Try removing the 'column' attribute from the 'collection' element.
It is useless for a nested result (see
http://www.mybatis.org/mybatis-3/sqlmap-xml.html).
I'll see if it's possible to raise more appropriate error later.

If it didn't solve the issue, please create SSCCE.
Here are some skeleton projects to make it a little bit easier.
https://github.com/harawata/mybatis-issues

Regards,
Iwao
> --
> You received this message because you are subscribed to the Google Groups
> "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mybatis-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Crater Void

unread,
Aug 9, 2016, 2:20:49 PM8/9/16
to mybatis-user
Thanks Iwao.  That worked!

Iwao AVE!

unread,
Aug 9, 2016, 9:07:04 PM8/9/16
to mybatis-user
Glad to know it worked :)
Thanks for the follow-up!

2016-08-10 3:20 GMT+09:00 Crater Void <crater...@gmail.com>:
> Thanks Iwao. That worked!
Reply all
Reply to author
Forward
0 new messages