New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sebdavid opened this Issue Oct 9, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@sebdavid
Copy link

sebdavid commented Oct 9, 2015

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.

@jamhall

This comment has been minimized.

Copy link

jamhall commented Jan 6, 2016

+1

I got burned by this; it took me quite a while to figure out what the problem was!

RokolyA94 added a commit to RokolyA94/mybatis-3 that referenced this issue Apr 24, 2017

@harawata harawata self-assigned this Nov 4, 2018

@harawata harawata added the enhancement label Nov 4, 2018

@harawata harawata added this to the 3.5.0 milestone Nov 4, 2018

@harawata harawata closed this in 94272d7 Nov 5, 2018

@harawata

This comment has been minimized.

Copy link
Member

harawata commented Nov 5, 2018

This should be fixed in the latest 3.5.0-SNAPSHOT.

I am not familiar with <discriminator /> and there is not many tests covering the spec.
Hope the change does not break anything. 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment