出现异常

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/mybatis/mapper/EmpMapper.xml
### The error occurred while processing mapper_resultMap[empAndDeptResultMapOne]_association[dept]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause:org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/mybatis/mapper/EmpMapper.xml'. 
Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mybatis.mapper.EmpMapper.empAndDeptResultMapOne

分析原因

Cause: java.lang.IllegalArgumentException: Result Maps collection
already contains value for com.mybatis.mapper.EmpMapper.
empAndDeptResultMapOne
翻译一下:原因:java.lang.IllegalArgumentException: Result Maps集合已经包含了com.mybatis.mapper.EmpMapper.
empAndDeptResultMapOne的值
说明: empAndDeptResultMapOne这个resultMap可能不唯一。

查看代码

<resultMap id="empAndDeptResultMapOne" type="Emp">
	<id property="eid" column="eid"></id>
	<result property="empName" column="emp_name"></result>
	<result property="age" column="age"></result>
	<result property="dept.did" column="did"></result>
</resultMap>

<resultMap id="empAndDeptResultMapOne" type="Emp">
	<id property="eid" column="eid"></id>
	<result property="empName" column="emp_name"></result>
	<result property="age" column="age"></result>
	<association property="dept" javaType="Dept">
		<id property="did" column="did"></id>
	</association>
</resultMap>

<select id="getEmpAndDept" resultMap="empAndDeptResultMapOne">
        select * from t_emp left join t_dept on t_emp.did = t_dept.did where t_emp.eid = #{eid}
</select>

出现了两个重复的empAndDeptResultMapOne,而resultMap 中的id是唯一标识,故出现错误,改名或者删除其中一个即可。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐