Mybatis3.2问题 标签collection使用有问题啊?

woainihuajia 2014-05-14 01:21:22
教师的xml
	<!-- Teacher结果集映射 -->
<resultMap id="teaResultMap" type="Teacher">
<!--教师自身的属性与数据库字段的映射。注意这里 用到了字段别名 -->
<id property="id" column="t_id" />
<result property="name" column="t_name" />
<result property="gender" column="t_gender" />
<result property="researchArea" column="t_research_area" />
<result property="title" column="t_title" />
<collection property="supStudents" ofType="Student"
resultMap="com.liu.dao.StudentMapper.studentResultMap">
</collection>
</resultMap>

学生的xml
<resultMap id="studentResultMap" type="Student">
<!--id映射 -->
<id property="userId" column="id" />
<!--普通属性映射 -->
<result property="name" column="name" />
<result property="gender" column="gender" />
<result property="major" column="major" />
<result property="grade" column="grade" />
<association property="supervisor" javaType="Teacher"
resultMap="com.liu.dao.TeacherMapper.teaResultMap"></association>
</resultMap>


教师的xml 第二种配置
<!-- Teacher结果集映射 -->
<resultMap id="teaResultMap" type="Teacher">
<!--教师自身的属性与数据库字段的映射。注意这里 用到了字段别名 -->
<id property="id" column="t_id" />
<result property="name" column="t_name" />
<result property="gender" column="t_gender" />
<result property="researchArea" column="t_research_area" />
<result property="title" column="t_title" />
<collection property="supStudents" ofType="Student"
resultMap="studentResultMap">
</collection>
</resultMap>
<resultMap id="studentResultMap" type="Student">
<!--id映射 -->
<id property="userId" column="id" />
<!--普通属性映射 -->
<result property="name" column="name" />
<result property="gender" column="gender" />
<result property="major" column="major" />
<result property="grade" column="grade" />
</resultMap>



最近学习mybatis 使用一对多 设置时遇到一个问题:
使用mybatis3.1.1 按照学生的xml 和教师的xml 就没问题
换成 mybatis3.2.6就出现问题了 教师的xml 必须改写为:教师的xml 第二种配置

这个是mybatis3.2的Bug 吗 ?
...全文
512 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
licho.sun 2014-12-21
  • 打赏
  • 举报
回复
引用 6 楼 woainihuajia 的回复:
对的 经核实确认 为Mybatis+Spring 时 不支持这种 教师的xml <collection 跨namespace的配置方式。 必须在当前的xml进行配置才可以。
我也遇到这个问题了,其实是两个配置文件形成了互相引用的问题,把其中一个xml文件里的resultMap,独立定义就可以了。不是collection不支持跨namespace的问题。
woainihuajia 2014-05-22
  • 打赏
  • 举报
回复
对的 经核实确认 为Mybatis+Spring 时 不支持这种 教师的xml <collection 跨namespace的配置方式。 必须在当前的xml进行配置才可以。
suciver 2014-05-16
  • 打赏
  • 举报
回复
没看出楼主的第一种和第二种xml配置有啥区别,第一种在resultMap那边就多了namespace.resultMapId,第二种没有跟上namespace而是把两个resultMap都写在同一个mapper.xml里面了。楼主是不是namespace不是第一种配置的那个
woainihuajia 2014-05-16
  • 打赏
  • 举报
回复
经核对确认 为Mybatis+Spring 时 报的错误。
woainihuajia 2014-05-16
  • 打赏
  • 举报
回复
报的是类里面的属性类型不对
woainihuajia 2014-05-16
  • 打赏
  • 举报
回复
Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property 'supStudents' of 'class com.liu.pojo.Teacher' with value 'Student [userId=8, name=小青, gender=女, major=计算机系, grade=2012, supervisor=null]' Cause: java.lang.IllegalArgumentException: argument type mismatch
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
	at com.sun.proxy.$Proxy4.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy5.queryByIdStudent(Unknown Source)
	at com.liu.test.selectTest.main(selectTest.java:30)
Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'supStudents' of 'class com.liu.pojo.Teacher' with value 'Student [userId=8, name=小青, gender=女, major=计算机系, grade=2012, supervisor=null]' Cause: java.lang.IllegalArgumentException: argument type mismatch
	at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:175)
	at org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:57)
	at org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:133)
darren中 2014-05-14
  • 打赏
  • 举报
回复
应该是的,能否贴下异常信息

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧