框架子查询问题.急

leafsoar 2010-02-25 07:18:17

<sqlMap namespace="sysRole">
<typeAlias alias="sysRole" type="com.klt.entity.SysRole"/>

<resultMap id="SysRoles" class="sysRole">
<result property="roleId" column="role_id"/>
<result property="roleName" column="role_name"/>
<result property="roleDesc" column="role_desc"/>
<result property="roleFlag" column="role_flag"/>

</resultMap>

<!-- Select with no parameters using the result map for Account class. -->
<select id="getAllSysRole" resultClass="SysRole" resultMap="SysRoles">
select * from sys_role
</select>
<select id="getSysRole" resultClass="SysRole" resultMap="SysRoles" parameterClass="int" >
select * from sys_role where role_id =#value#
</select>

</sqlMap>


<sqlMap namespace="sysRoleRight">
<typeAlias alias="sysRoleRight" type="com.klt.entity.SysRoleRight" />

<resultMap id="SysRoleRights" class="sysRoleRight">
<result property="rfId" column="rf_id" />
<result property="rfRole" select="sysRole.getSysRole" column="rf_role_id" />
</resultMap>

<!-- Select with no parameters using the result map for Account class. -->
<select id="getAllSysRoleRight" resultClass="SysRoleRight"
resultMap="SysRoleRights">
select * from sys_role_right
</select>
<select id="getSysRoleRight" resultClass="SysRoleRight"
parameterClass="int" resultMap="SysRoleRights">
select * from sys_role_right where rf_id=#value#
</select>

</sqlMap>




ApplicationContext cxt = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
SysRoleRightDAO sy = (SysRoleRightDAO)cxt.getBean("sysRoleRightDAO");
SysRoleRight rr = sy.getSysRoleRightByRfId(399);
System.out.println(rr.getRfId());

这样写报错.
如果把下面那个xml文件中
"<result property="rfRole" select="sysRole.getSysRole" column="rf_role_id" />"
删去的话.就没有问题.也就是说外键问题.在ibatis框架中怎么写外键对象的赋值配置.
单独调用第一个xml中的"getSysRole"也没有问题.
错误信息如下.


log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];
--- The error occurred in com/klt/entity/map/SysRoleRight.xml.
--- The error occurred while applying a result map.
--- Check the sysRoleRight.SysRoleRights.
--- Check the result mapping for the 'rfRole' property.
--- Cause: com.ibatis.sqlmap.client.SqlMapException: There is no statement named sysRole.getSysRole in this SqlMap.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/klt/entity/map/SysRoleRight.xml.
--- The error occurred while applying a result map.
--- Check the sysRoleRight.SysRoleRights.
--- Check the result mapping for the 'rfRole' property.
--- Cause: com.ibatis.sqlmap.client.SqlMapException: There is no statement named sysRole.getSysRole in this SqlMap.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:124)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:271)
at com.klt.dao.impl.SysRoleRightDAOImpl.getSysRoleRightByRfId(SysRoleRightDAOImpl.java:19)
at com.klt.test.Test.main(Test.java:18)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/klt/entity/map/SysRoleRight.xml.
--- The error occurred while applying a result map.
--- Check the sysRoleRight.SysRoleRights.
--- Check the result mapping for the 'rfRole' property.
--- Cause: com.ibatis.sqlmap.client.SqlMapException: There is no statement named sysRole.getSysRole in this SqlMap.
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
... 3 more
Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no statement named sysRole.getSysRole in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:293)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.getMappedStatement(SqlMapClientImpl.java:202)
at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getNestedSelectMappingValue(BasicResultMap.java:471)
at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getResults(BasicResultMap.java:340)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:381)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 9 more


在ibatis框架中怎么配置外键的.看了很多例子,都没有找到原因.

如果还需要什么信息请留言.在线等解决.....
...全文
68 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
leafsoar 2010-02-25
  • 打赏
  • 举报
回复


insert into sys_user (
user_name,
user_password,
user_flag,
user_role_id
) values (
#userName#,
#userPassword#,
#userFlag#,
#userRole##roleId# //这里想表达的是userRole是个对象.怎么取出里面的字段roleID,这样使错的,正确的应该怎么写
)
xiaoguan_Java 2010-02-25
  • 打赏
  • 举报
回复
ding ding ./............

81,122

社区成员

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

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