Skip to content

BaseBuilder#resolveTypeHandler does not account javaType for caching handlers #995

@Hubbitus

Description

@Hubbitus

MyBatis version

3.4.2

Database vendor and version

Postgres 9.6

Steps to reproduce

I have result map with 2 Enums in it for handling in sumulationaly like that:

    <resultMap id="groupPlotFactMap" type="ru.rlh.egais.portal.api.dto.bo.PlotFact">
        <id column="pf_document_base_fkey" property="documentId"/>
        <id column="pf_unit" property="unit" typeHandler="EnumTypeHandler"/>
        <id column="pf_meta" property="meta" typeHandler="EnumTypeHandler"/>
    </resultMap>

And class:

public class PlotFact {
    private Unit unit;
    private FactMeta meta;
}

Expected result

Both fields mapped.

Actual result

Exception:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'pf_meta' from result set.  Cause: java.lang.IllegalArgumentException: No enum constant ru.rlh.egais.portal.api.dto.enumeration.Unit.GROUP
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
    at com.sun.proxy.$Proxy1029.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
    at com.sun.proxy.$Proxy1115.search(Unknown Source)
    at ru.rlh.egais.portal.backend.service.PlotFactService.lambda$find$0(PlotFactService.java:82)
    at ru.rlh.egais.portal.backend.util.SearchUtils.makeSearch(SearchUtils.java:38)
   at ru.rlh.egais.portal.backend.service.PlotFactService.find(PlotFactService.java:81)

Indeed, database value GROUP belongs to secong enum ru.rlh.egais.portal.api.dto.enumeration.FactMeta instead of ru.rlh.egais.portal.api.dto.enumeration.Unit.

I start debugging and found what org.apache.ibatis.type.EnumTypeHandler instantiated once. And placed into registry by handler ignore handled target class. In source code even comment about that:

// javaType ignored for injected handlers see issue #746 for full detail
TypeHandler<?> handler = typeHandlerRegistry.getMappingTypeHandler(typeHandlerType);

But issue #746 redirect to pull request #746 which seams irrelevant.

So could you please clarify why so?

If it desired I could try provide pull request for change caching.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions