ibatis查询时,返回类型中有其他对象,映射xml文件中怎么写?

代码养殖员 2011-12-19 11:47:39
有一张user表,有userID typeName 字段 ,其中typeName 是 type表中的字段
我建实体类时先创建了Type类然后,User类中包含了Type类的对象。

在user.xml文件中写查询全部user表信息时
<select id="getAllUser" resultClass="User">
select * from user
</select>

会报错
--- The error occurred in User.xml.
--- The error occurred while applying a result map.
--- Check the getAllUser-AutoResultMap.
--- Check the result mapping for the 'type' property.

我想是因为我设置的返回类型是User。但是User对象中的type属性不能够接收,ibatis查询User表时查到的typeName
我尝试着
<select id="getAllUser" resultClass="User">
select userID,type.typeName from user
</select>
会报错说:
--- Cause: java.sql.SQLException: ORA-00904: "type"."typeName":标识符无效
有什么解决方法呀??
...全文
300 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
代码养殖员 2011-12-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xc2010_k 的回复:]
Java code


<resultMap type="java.util.HashMap" id="User">
<result column="id" property="id"></result>
<result column="name" property="name"></result>
<result column="age" property="age"></resul……
[/Quote]

就是用这个,
column="typeName" property用 type.typeName就可以了
nicklename 2011-12-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xc2010_k 的回复:]
Java code
[/Quote]
<resultMap type="java.util.HashMap" id="User">
<result column="id" property="id"></result>
<result column="name" property="name"></result>
<result column="age" property="age"></result>……
XC2010_K 2011-12-20
  • 打赏
  • 举报
回复

<resultMap type="java.util.HashMap" id="User">
<result column="id" property="id"></result>
<result column="name" property="name"></result>
<result column="age" property="age"></result>
</resultMap>

<select id="getUser" resultMap="User">
SELECT id,name,age FROM user
</select>

照这么做,试试。
Inhibitory 2011-12-20
  • 打赏
  • 举报
回复
看文档里的ResultMap
代码养殖员 2011-12-19
  • 打赏
  • 举报
回复
是在查的时候
List<User> list = sqlMapClient.queryForList("getAllUser");
报错

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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