mybatis xml inspection error with "id should be defined"

676 Views Asked by At

There's web project with Spring and MyBatis. I use IntelliJ IDEA for development. IDEA cannot correctly inspect MyBatis beans and produces annoying underscorings.

Inspection comment: "id should be defined"

I have checked the file "mybatis-3-mapper.dtd" and haven't found any reason why idea inspects "id should be defined".

I think this inspects is wrong,but I don't know how to close this inspects.

If anyone know how to fix this problem,please help me.Thanks!

<insert id="insert" useGeneratedKeys="true" parameterType="com.lingshou.commodity.po.id.CommSerialNoPO">
    INSERT INTO comm_serial_no (
        biz_type,
        biz_seq,
        create_by,
        update_by,
        create_time,
        update_time,
        is_delete
    ) VALUES (
        #{bizType},
        #{bizSeq},
        #{createBy},
        #{updateBy},
        #{createTime},
        #{updateTime},
        #{delete}
    );
    <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER">
        SELECT LAST_INSERT_ID();
    </selectKey>
</insert>

[Inspection][https://i.stack.imgur.com/NSrjp.png]

1

There are 1 best solutions below

1
On

Since you added the < selectKey > tag you are telling MyBatis to retrieve the auto-populated column id (keyProperty="id") after the insert takes place. Probably that column is an identity one, right?

Does your class com.lingshou.commodity.po.id.CommSerialNoPO have a property named id or setter setId(...)?