错误原因



这个错误通常表示在解析 Mybatis 映射文件(Mapper XML)时出现了问题,可能的原因有两个:

  1. 集合属性缺少 javaType 或 resultMap 属性:该错误信息显示了 "Ambiguous collection type for property 't_emp'. You must specify 'javaType' or 'resultMap'",表明 t_emp 属性的集合类型不明确,需要指定 javaType 或 resultMap。这通常发生在映射文件中的集合属性没有指定 javaType 或 resultMap,并且 Mybatis 无法自动推断出其类型时。要解决这个问题,需要在映射文件中为集合属性添加 javaType 或 resultMap,明确其类型。

  2. 映射文件语法错误:另外一个可能的原因是映射文件中存在语法错误,导致 Mybatis 无法正确解析该文件。在这种情况下,需要仔细检查映射文件的语法是否正确,以及是否存在语法错误。

针对以上原因,你可以参照以下方法进行排查和修复:

  1. 检查集合属性是否指定了 javaType 或 resultMap,如果没有,则添加相应的属性定义。
  2. 检查映射文件是否存在语法错误,例如元素是否正确闭合、属性是否正确赋值等。
  3. 确保 Mybatis 版本与依赖库的版本相匹配,版本不匹配也可能导致解析错误。
  4. 尝试使用 Mybatis 提供的工具进行调试和分析,例如使用 Mybatis Generator 自动生成 Mapper 类或 XML 文件,查看其生成的代码是否符合预期。

示例纠正后的映射文件:

<resultMap id="deptAndEmpResultMap" type="com.north.model.Dept">
<id property="deptno" column="deptno"/>
<result property="dname" column="dname"/>
<result property="loc" column="loc"/>
<collection property="t_emp" resultMap="empResultMap"/>
</resultMap> <resultMap id="empResultMap" type="com.north.model.Emp">
<id property="empno" column="empno"/>
<result property="ename" column="ename"/>
<result property="job" column="job"/>
</resultMap>

这里 collection 配置项的 resultMap 属性指向了指定类型的映射配置。

解决方案

吐槽一下自己 : 自己真的有被自己给蠢到 , 写的时候不注意

在实体类当中添加另一个实体类进行封装 , 然后再进行查询

    private Emp emp;

    public Emp getEmp() {
return emp;
} public void setEmp(Emp emp) {
this.emp = emp;
}

最终问题得到解决

查询结果显示 :

Cause: org.apache.ibatis.builder.BuilderException: Ambiguous collection type for property 'emps'. You must specify 'javaType' or 'resultMap'的更多相关文章

  1. mybatis <fireach> 拼接sql语句 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'in'. Cause:

    <select id="getUserIn" parameterType="QueryVo" resultMap="userMap"& ...

  2. ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.

    在做多表映射查询时,在同一个resultMap中写了1:1映射和1:n映射,结果测试时报错如下: org.apache.ibatis.exceptions.PersistenceException: ...

  3. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xm

    mybatis解析xml配置文件出现异常: org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession. ...

  4. org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.问题思路

    15:36:34,549 WARN DefaultListableBeanFactory:1416 - Bean creation exception on FactoryBean type chec ...

  5. 解决:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'requestMap.maintenancename != null and requestMap.maintenance

    异常如下:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.Builde ...

  6. The error may exist in com/bjpowernode/dao/StudentDao.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderExcept

    The error may exist in com/bjpowernode/dao/StudentDao.xml### Cause: org.apache.ibatis.builder.Builde ...

  7. mybatis异常:nested exception is org.apache.ibatis.builder.BuilderException: Error resolving JdbcType

    异常详细 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.Builde ...

  8. ### Error building SqlSession. ### The error may exist in SQL Mapper Configuration ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibat

    这是一个由粗心导致的错误,具体报错如下: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSessio ...

  9. Error building SqlSession. ### The error may exist in dao/UserMapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration(2 字节的 UTF-8 序列的字节 2 无效。)

    关于在学习Mybatis框架时运行报错 Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error building ...

  10. 报错 ———— Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

    报错 <?xml version="1.0" encoding="UTF-8"?>  必须是XML文件的第一个元素且前面不能空格. ### Erro ...

随机推荐

  1. 源码安装slurm

    一.源码安装munge 1.下载munge 下载地址:https://github.com/dun/munge/releases 2.安装编译 tar -Jxvf munge-0.5.15.tar.x ...

  2. xtrabackup+MySQL8全备+增备脚本

    问题描述:运用xtrabackup进行mysql全备,mysql8之前使用的是innodbxtrabackup,mysql8之后开始使用xtrabackup,innobackupex把功能都集成到xt ...

  3. MySQL(一)Linux下MySQL的安装

    Linux下MySQL的安装 1 MySQL的安装 1.1 Linux系统以及工具的准备 这里使用两台CentOS7虚拟机,一台安装8.0版本,另一台克隆的虚拟机安装5.7版本 克隆的虚拟机需要进行配 ...

  4. R的基本用法2

    title: "Lectures" author: '01' date: "2022-09-23" output: pdf_document knitr::op ...

  5. vsftpd[9183]: warning: can't get client address: Socket operation on non-socket

    今天在linux redhat7.2下执行service vsftpd start一直不能开启vsftpd服务,本来怀疑SELINUX的问题(其他ftp下载问题可以看下我的另外一篇博客Linux下ft ...

  6. 【解决方法】windows连接域时报错:An Active Directory Domain Controller(AD DC) for the domain“chinaskills.com“....

    目录-快速跳转 问题描述 原因分析: 解决方案: 附言: 问题描述 操作环境与场景: 在 VM 内 windos 2019 在连接到域时,提示报错: An Active Directory Domai ...

  7. nuxt.js项目中全局捕获异常并生成错误日志全过程

    需求:客户在使用过程中页面报错时,可以生成错误记录传回服务器,以便改进. 步骤: 一.全局捕获异常, 二.发送到服务端, 三.生成错误日志. 一.全局捕获异常 如图,vue提供了errorHandle ...

  8. 2023-02-18:ffmpeg是c编写的音视频编解码库,请问用go语言如何调用?例子是03输出版本号。

    2023-02-18:ffmpeg是c编写的音视频编解码库,请问用go语言如何调用?例子是03输出版本号. 答案2023-02-18: 用 github.com/moonfdd/ffmpeg-go 这 ...

  9. 2021-04-08:给定一个单链表的头节点head,请判断该链表是否为回文结构。

    2021-04-08:给定一个单链表的头节点head,请判断该链表是否为回文结构. 福大大 答案2021-04-08: 1.找中点. 2.按中点切分成两个链表. 3.反转右边链表. 4.相等判断. 5 ...

  10. 2022-01-18:将数组分成两个数组并最小化数组和的差。 给你一个长度为 2 * n 的整数数组。你需要将 nums 分成 两个 长度为 n 的数组,分别求出两个数组的和,并 最小化 两个数组和之

    2022-01-18:将数组分成两个数组并最小化数组和的差. 给你一个长度为 2 * n 的整数数组.你需要将 nums 分成 两个 长度为 n 的数组,分别求出两个数组的和,并 最小化 两个数组和之 ...