mybatis 引用对象属性映射错误 or could not be found for the javaType (xxx.model) : jdbcType (null) combination.

宽为限 紧用功 工夫到 滞塞通

使用mybatis框架时遇到的一个错误,记录一下
org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘productType’. It was either not specified and/or could not be found for the javaType (xxx.pojo.ProductType) : jdbcType (null) combination.

错误信息是mybatis没找到对应的jdbcTye,这里我就纳闷了,好好的对象怎么会需要映射了?以前都不用的啊???
打开该报错类的配置文件和实体类看看

productMain.xml

...
    <resultMap type="product" id="productMap">
        ...
        <association property="productType" column="product_type"
            select="xxx.mapper.ProductTypeMapper.getById" />

    </resultMap>
    ...

ProductMain.java

...
    /**
     * 商品分类
     */
    private ProductType productType;

    public ProductType getProductType() {
        return productType;
    }

    public void setProductType(ProductType productType) {
        this.productType = productType;
    }
...

没发现什么毛病,productType 类型是这样的,,
看到javaType (xxx.pojo.ProductType)这个错好像发现了什么,,好端端的怎么突然要映射了呢? 莫非它不是一个属性了?,,,突然想起这个,别名!!!

sqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

    <!-- 设置 -->
    <settings>
        <!-- 这个配置使全局的映射器启用或禁用缓存 -->
        <setting name="cacheEnabled" value="true" />
        <!-- 允许JDBC支持生成的键 -->
        <setting name="useGeneratedKeys" value="true" />
        <!-- 配置默认的执行器 -->
        <setting name="defaultExecutorType" value="REUSE" />
        <!-- 全局启用或禁用延迟加载 -->
        <setting name="lazyLoadingEnabled" value="true" />
        <!-- 设置超时时间,它决定驱动等待一个数据库响应的时间 -->
        <setting name="defaultStatementTimeout" value="25000" />
    </settings>

    <!-- 配置别名 -->
    <typeAliases>
        <typeAlias alias="user" type="xxx.pojo.ProductUser" />
        <typeAlias alias="product" type="xxx.pojo.ProductMain" />
        <typeAlias alias="productType" type="xxx.pojo.ProductType" />
        <typeAlias alias="productLabel" type="xxx.pojo.ProductLabel" />
        <typeAlias alias="productImage" type="xxx.pojo.ProductImage" />
    </typeAliases>
...
<typeAlias alias="productType" type="xxx.pojo.ProductType" />

<association property="productType" column="product_type"
            select="xxx.mapper.ProductTypeMapper.getById" />

额,,重名了!这里写图片描述
改一个名字重启一下就OK啦 \(^o^)/YES!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值