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

来源:互联网 发布:荷塘月色淘宝论坛上 编辑:程序博客网 时间:2024/05/29 04:08
宽为限 紧用功 工夫到 滞塞通

使用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!

阅读全文
1 0