代码是这样的:
1、mysql的一个自定义函数:
CREATE FUNCTION partinc.`udf_getUrlPathCaption`(
        v_nodeId INT
    ) RETURNS varchar(3000) CHARSET gbk
BEGIN
DECLARE nodeIds varchar(3000);-- 所有节点的id字符串
DECLARE nodeId_temp varchar(3000);-- 
DECLARE nodeNames varchar(3000);-- 返回的节点名称串
set nodeIds = '-1';
set nodeId_temp=concat(v_nodeId);
while !isnull(nodeId_temp) do
set nodeIds = concat(nodeIds,',',nodeId_temp);
select group_concat(Parent_ID) into nodeId_temp from CM_BT_TreeNode where FIND_IN_SET(Node_Id,nodeId_temp);
end while;
select group_concat(node_Name Separator '/') into nodeNames from CM_BT_TreeNode where FIND_IN_SET(Node_Id,nodeIds);
return nodeNames;
END;2、iBATIS映射文件中的语句:
<select id="getUrlPathCaption" parameterClass="string" resultClass="string">
        select udf_getUrlPathCaption(#nodeId:varchar#)
</select>3、执行后报的错误:
[ERROR] 2010-01-04 16:12:27(CompoundRootAccessor.java:getProperty:107)Caught an Ognl exception while getting property urlPathCaption
ognl.OgnlException: urlPathCaption [com.chinadcl.partinc.common.util.exception.BusinessException: 查询数据出错,原因为:  
--- The error occurred in config/NoUse.xml.  
--- The error occurred while applying a result map.  
--- Check the CM_BT_TreeNode.getUrlPathCaption-AutoResultMap.  
--- Check the result mapping for the 'udf_getUrlPathCaption('3663')' property.  
--- Cause: java.sql.SQLException: Column 'udf_getUrlPathCaption('3663')' not found.]4、说明:
在mysql中执行这个函数没有任何问题。
在应用中第一次调用这条语句的时候也没有问题。
当其他功能也要去调用此语句的时候就出现如上问题了。而参数中的3663其实是上一次执行的那个参数,不是本次传入的参数。
当调试的时候参数传值是正确的,但报错后在控制台打出来就如上面的了。

解决方案 »

  1.   

    可以确定,这里和你mysql有问题
    <select id="getUrlPathCaption" parameterClass="string" resultClass="string">
            select udf_getUrlPathCaption(#nodeId:varchar#)
    </select> 你可以先写个死参数在这里调试下
    入参类型正确吗iBATIS 参数#nodeId#这样写的吧
      

  2.   

    v_nodeId INT 你的存储过程需要的是int的参数,为什么你传递的是string呢?
    改为:<select id="getUrlPathCaption" parameterClass="Integer" resultClass="string"> 
            select udf_getUrlPathCaption(#nodeId#) 
    </select> 
      

  3.   

    吓我一跳,还以为是mysql有问题了,正准备学呢
      

  4.   

    问题已经解决了,但不清楚是为什么?知道的请告知!
    解决如下:
    <select id="getUrlPathCaption" parameterClass="string" resultClass="string"> 
            select udf_getUrlPathCaption(#nodeId:varchar#) as Node_Name
    </select> 
      

  5.   

    参数类型这些无所谓的,因为都是数字,定义为varchar和int有什么区别呢?
      

  6.   


    可能指定了 resultClass="string" ,需要显式返回一个字符串,要求用别名代替存储过程调用?
    猜的,不明白,没玩过这么高级的
      

  7.   

    resultMap 里column 是Node_Name