我原来用的是mysql+ibatis ,最近换成:oracle+ ibatis,原来是可以使用的,但是换成了oracle后,感觉##不正确,不能选择出正确的数据:
resultMap是:
<resultMap class="menu" id="menuResult">
<result column="MENUID" property="menuId" />
<result column="MENUNAME" property="menuName" />
<result column="TYPE" property="type" />
<result column="ACTIONID" property="action" select="menu.getActionById" />
<result column="PARENTID" property="parentId" />
<result column="SORTORDER" property="sortOrder" />
<result column="REMARK" property="remark" />
</resultMap>
<select id="getMenu" resultMap="menuResult">
select * from sys_menu
<dynamic prepend="where">
<isNotEmpty property="menu.menuId" prepend="and">
menuId=#menu.menuId#
</isNotEmpty>
<isNotEmpty property="menu.parentId" prepend="and">
parentId=#menu.parentId#
</isNotEmpty>
<isNotEmpty property="roleList" prepend="and">
exists (select id from sys_rolemenu where
sys_rolemenu.menuid=sys_menu.menuid
<iterate property="roleList" prepend="and" open="(" close=")"
conjunction="or">
roleid=#roleList[].roleId#
</iterate>
)
</isNotEmpty>
</dynamic>
order by sortOrder
</select>
执行过程:
DEBUG - Getting transaction for [net.sansheng.scm.system.service.MenuManageService.getMenuTree]
DEBUG - {conn-100033} Connection
DEBUG - {conn-100033} Preparing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@8ca0d9] for key [org.apache.commons.dbcp.BasicDataSource@abc00] bound to thread [http-8080-2]
DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@8ca0d9] for key [org.apache.commons.dbcp.BasicDataSource@abc00] bound to thread [http-8080-2]
DEBUG - {pstm-100034} Executing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - {pstm-100034} Parameters: [TREEROOT]
DEBUG - {pstm-100034} Types: [java.lang.String]
DEBUG - {rset-100035} ResultSet
可以看出是出入了参数的[TREEROOT] 的,但是选择不出结果:
在oracle中:
select * from sys_menu where parentId='TREEROOT' 是可以选择出数据的;
感觉传递给oracle中,没有将TREEROOT 这个参数增加单引号的感觉,请教大师??急!!!
自己测试了一下,直接写条件是可以的:
DEBUG - {conn-100036} Preparing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@49c5cd] for key [org.apache.commons.dbcp.BasicDataSource@16a0676] bound to thread [http-8080-6]
DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@49c5cd] for key [org.apache.commons.dbcp.BasicDataSource@16a0676] bound to thread [http-8080-6]
DEBUG - {pstm-100037} Executing Statement: select * from sys_menu where parentid='TREEROOT' order by sortOrder
DEBUG - {pstm-100037} Parameters: []
可以选择出数据:
另外:插入数据是可以的:
DEBUG - {pstm-100033} Executing Statement: insert into sys_log (id, action_name, employeeId, oper_time) values (?, ?, ?, ?)
DEBUG - before Locale=zh_CN
DEBUG - {pstm-100033} Parameters: [F3D3723DB4E74C2992EA938BB0E08793, workList_toWorkList.do, 1, 2012-06-17 10:57:47.484]
这个可以,对应的xml是:
<insert id="addLog" parameterClass="log">
insert into sys_log (id,
action_name, employeeId, oper_time)
values (#id#,
#actionName#,
#employeeId#,
#operTime#)
</insert>
可以执行成功,那么我就怀疑是不是我原来的mysql 默认的是自动在字符上增加的引号是:"" ,而oracle 需要的是'',请大师给我分析一下如何解决?
4 个解决方案
#1
我自己再试了一下,如果将上面的语句:
就会提示:
--- The error occurred while applying a parameter map.
--- Check the workList.getMenu-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "treeRoot": 标识符无效
也就是说在语句中增加""是不能通过的,但是上面的:
DEBUG - {pstm-100034} Executing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - {pstm-100034} Parameters: [TREEROOT]
DEBUG - {pstm-100034} Types: [java.lang.String]
DEBUG - {rset-100035} ResultSet
没有提示这个信息? 但是还是不知道如何解决这个问题,这个问题是根本问题,不解决就没有办法往下进行了,大师们,帮助!!!
select * from sys_menu where parentid='TREEROOT' order by sortOrder语句改成:
<select id="getMenu" resultClass="workmenu">
select * from sys_WorkMenu where parentid="TREEROOT"
order by sortOrder
</select>
就会提示:
--- The error occurred while applying a parameter map.
--- Check the workList.getMenu-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "treeRoot": 标识符无效
也就是说在语句中增加""是不能通过的,但是上面的:
DEBUG - {pstm-100034} Executing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - {pstm-100034} Parameters: [TREEROOT]
DEBUG - {pstm-100034} Types: [java.lang.String]
DEBUG - {rset-100035} ResultSet
没有提示这个信息? 但是还是不知道如何解决这个问题,这个问题是根本问题,不解决就没有办法往下进行了,大师们,帮助!!!
#2
Oracle中字符串必须用 单引号,所以你修改错了,应该是:
<select id="getMenu" resultClass="workmenu">
select * from sys_WorkMenu where parentid='TREEROOT'
order by sortOrder
</select>
#3
另一种恶心点的测试方法是:
<isNotEmpty property="menu.parentId" prepend="and">
parentId='$menu.parentId$'
</isNotEmpty>
<isNotEmpty property="menu.parentId" prepend="and">
parentId='$menu.parentId$'
</isNotEmpty>
#4
谢谢,forgetsam(懒猫),的确是我的字段属性错误了,parentId这个字段需要定义成 varchar2,但是我定义成了char,导致选择不出来数据。
#1
我自己再试了一下,如果将上面的语句:
就会提示:
--- The error occurred while applying a parameter map.
--- Check the workList.getMenu-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "treeRoot": 标识符无效
也就是说在语句中增加""是不能通过的,但是上面的:
DEBUG - {pstm-100034} Executing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - {pstm-100034} Parameters: [TREEROOT]
DEBUG - {pstm-100034} Types: [java.lang.String]
DEBUG - {rset-100035} ResultSet
没有提示这个信息? 但是还是不知道如何解决这个问题,这个问题是根本问题,不解决就没有办法往下进行了,大师们,帮助!!!
select * from sys_menu where parentid='TREEROOT' order by sortOrder语句改成:
<select id="getMenu" resultClass="workmenu">
select * from sys_WorkMenu where parentid="TREEROOT"
order by sortOrder
</select>
就会提示:
--- The error occurred while applying a parameter map.
--- Check the workList.getMenu-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "treeRoot": 标识符无效
也就是说在语句中增加""是不能通过的,但是上面的:
DEBUG - {pstm-100034} Executing Statement: select * from sys_menu where parentId=? order by sortOrder
DEBUG - {pstm-100034} Parameters: [TREEROOT]
DEBUG - {pstm-100034} Types: [java.lang.String]
DEBUG - {rset-100035} ResultSet
没有提示这个信息? 但是还是不知道如何解决这个问题,这个问题是根本问题,不解决就没有办法往下进行了,大师们,帮助!!!
#2
Oracle中字符串必须用 单引号,所以你修改错了,应该是:
<select id="getMenu" resultClass="workmenu">
select * from sys_WorkMenu where parentid='TREEROOT'
order by sortOrder
</select>
#3
另一种恶心点的测试方法是:
<isNotEmpty property="menu.parentId" prepend="and">
parentId='$menu.parentId$'
</isNotEmpty>
<isNotEmpty property="menu.parentId" prepend="and">
parentId='$menu.parentId$'
</isNotEmpty>
#4
谢谢,forgetsam(懒猫),的确是我的字段属性错误了,parentId这个字段需要定义成 varchar2,但是我定义成了char,导致选择不出来数据。