Skip to content

ResultMap, discriminator association, NullPointerException when no resultType set #486

@sebdavid

Description

@sebdavid

Hi !
I'm using mybatis 3.3.0.
The following mapper generates a NPE when used, because no resultType attribute is set on the <case> tags. The aim is to fill an interface/abstract/parent object with the right implementation :

<resultMap type="Owner" id="ownerMap">
    <id property="id" column="id" />
    <result property="name" column="name" />
    <discriminator javaType="string" column="vehicle_type">
        <case value="car">
            <association property="vehicle" column="vehicle_id" select="CarMapper.get" />
        </case>
        <case value="truck">
            <association property="vehicle" column="vehicle_id" select="TruckMapper.get" />
        </case>
    </discriminator>
</resultMap>

To make it working, the attribute resultType="Owner" must be set on the <case> tags, although it is not marked as required :

<resultMap type="Owner" id="ownerMap">
    <id property="id" column="id" />
    <result property="name" column="name" />
    <discriminator javaType="string" column="vehicle_type">
        <case value="car" resultType="Owner">
            <association property="vehicle" column="vehicle_id" select="CarMapper.get" />
        </case>
        <case value="truck" resultType="Owner">
            <association property="vehicle" column="vehicle_id" select="TruckMapper.get" />
        </case>
    </discriminator>
</resultMap>

It would be nice if, when the resultType attribute is not set, it automatically references the type set on the resultMap.

Metadata

Metadata

Assignees

Labels

enhancementImprove a feature or add a new feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions