Mapper icon indicating copy to clipboard operation
Mapper copied to clipboard

tk.mybatis.mapper.MapperException: 当前实体类不包含名为parentId的属性! 属性名不能带id么?

Open ITDragonBlog opened this issue 7 years ago • 6 comments

版本:mapper-spring-boot-starter:2.0.4 发现一个问题:若实体类中属性名中如果带有id,都会提示:当前实体类不包含名为xxx的属性!

ITDragonBlog avatar Sep 12 '18 06:09 ITDragonBlog

能不能提供完整的异常信息?

abel533 avatar Sep 26 '18 05:09 abel533

你这个是不是因为你的parentId的类型是基本数据类型? 我刚遇到这样的问题,在debug里面发现属性数据类型是基本类型的在proptyMap里面都不存在,修改成其对应的包装类型后就不会报这个错了。 这个应该是一个bug。

后来跟踪的时候(EntityHelper-->EntityResolve->DefaultEntityResolve),发现默认实现里面有对是不是数据是简单类型还是复杂类型有做处理。(具体的还未细看)。

zw231212 avatar Nov 27 '18 10:11 zw231212

补充,在DefaultEntityResolve中,第74行for循环里(如下所示),基本数据类型会被忽略(这里检查了几个配置与和数据类型,初入这段代码没懂这些配置的作用)

for (EntityField field : fields) {
            //如果启用了简单类型,就做简单类型校验,如果不是简单类型,直接跳过
            //3.5.0 如果启用了枚举作为简单类型,就不会自动忽略枚举类型
            //4.0 如果标记了 Column 或 ColumnType 注解,也不忽略
            if (config.isUseSimpleType()
                    && !field.isAnnotationPresent(Column.class)
                    && !field.isAnnotationPresent(ColumnType.class)
                    && !(SimpleTypeUtil.isSimpleType(field.getJavaType())
                    ||
                    (config.isEnumAsSimpleType() && Enum.class.isAssignableFrom(field.getJavaType())))) {
                continue;
            }
            processField(entityTable, field, config, style);
        }

zw231212 avatar Nov 27 '18 11:11 zw231212

基本类型?贴个代码看看。

abel533 avatar Dec 08 '18 02:12 abel533

基本类型?贴个代码看看。

项目的依赖为:

compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.2'
    compile group: 'tk.mybatis', name: 'mapper-spring-boot-starter', version: '2.1.0'
    compile ("com.github.pagehelper:pagehelper-spring-boot-starter:1.2.3"){
        exclude group: 'org.mybatis.spring.boot', module: 'mybatis-spring-boot-starter' //by both name and group
    }

在混合有基本数据类型时的model(15个属性,4个基本类型): model

mapper是这样的: mapper

在service里面是这样的:

siteid_example

然后debug后,example里面的propMap只有11个: example_debug 请求结果是: example_debug_result1

把那四个基本类型更换为相应的包装类型后,如下所示(这里15个属性都被加载了): example_debug2 查询结果为: example_debug_result2

从这里来看基本类型确实在项目启动后就没有被加载到propMap里面,不知道是不是要设置什么?

zw231212 avatar Dec 10 '18 10:12 zw231212

实体和propertyMap分别是: image 请求结果是: image 两个以ID结尾的都不可以

inner-kernel avatar Jul 18 '20 02:07 inner-kernel