81,092
社区成员
发帖
与我相关
我的任务
分享
<!-- 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>
<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>
<!-- 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>
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)