ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Hamacher" <eric.hamac...@enetrix.com>
Subject Arrays of Objects From a Oracle Stored Procedure
Date Thu, 04 Dec 2008 21:26:01 GMT
Hello:

 

I am having difficulty with TypeHandlerCallback.getResult().  I have two
arrays of objects being returned by a stored procedure.  Here is the sql
map:

 

   <parameterMap id="codeRefMap" class="map">

        <parameter property="codeDomainName"
jdbcType="VARCHAR"           javaType="java.lang.String" mode="IN"/>

 

        <parameter property="codeNameValueObjectARRAY"
jdbcType="NAME_VALUE_OBJ_TAB" typeName="NAME_VALUE_OBJ_TAB"
typeHandler="ibatis.NameValueArrayTypeHandlerCallback" mode="IN"/>

 

        <parameter property="codeRefObjectARRAY"
jdbcType="CODE_REF_OBJ_TAB"   typeName="CODE_REF_OBJ_TAB"
typeHandler="ibatis.CodeRefArrayTypeHandlerCallback" mode="INOUT"/>

 

        <parameter property="errorFlag"
jdbcType="VARCHAR"           javaType="java.lang.String" mode="OUT"/>

 

        <parameter property="errorARRAY"
jdbcType="ERROR_OBJ_TAB"      typeName="ERROR_OBJ_TAB"
typeHandler="ibatis.ErrorArrayTypeHandlerCallback" mode="OUT"/>

   </parameterMap>

   

      <procedure id="storedInfo" parameterMap="codeRefMap">

            {call aProcedure(?,?,?,?,?) }

   </procedure>

 

 

The Oracle type CODE_REF_OBJ_TAB is an array which maps to an array of
CodeRefObject obejcts in Java.  Similarly, the Oracle type ERROR_OBJ_TAB
is an array which maps to an array of ErrorObject objects in Java.  The
following is an excerpt from CodeRefArrayTypeHandlerCallback which
successfully casts results to CodeRefObject objects:

 

    static {

        JdbcTypeRegistry.setType("CODE_REF_OBJ", OracleTypes.STRUCT);

        JdbcTypeRegistry.setType("CODE_REF_OBJ_TAB", OracleTypes.ARRAY);

    }

 

    public Object getResult(ResultGetter resultGetter) throws
SQLException {

        Array array = resultGetter.getArray();

        if (array == null) {

            return null;

        }

        else {

            List<CodeRefObject> croList = new
ArrayList<CodeRefObject>();

           Object[] objectArray = (Object[]) array.getArray();

            for (Object o: objectArray) {

                CodeRefObject cro = (CodeRefObject) o;

               croList.add(cro);

            }

            return croList;

            

        }

    }

 

However, the same code in ErrorArrayTypeHandlerCallback fails with a
"java.lang.ClassCastException: oracle.sql.STRUCT" at the line
"ErrorObject eo = (ErrorObject) o;" line.  Here is
ErrorArrayTypeHandlerCallback:

 

 

    static {

        JdbcTypeRegistry.setType("ERROR_OBJ", OracleTypes.STRUCT);

        JdbcTypeRegistry.setType("ERROR_OBJ_TAB", OracleTypes.ARRAY);

    }

 

    public Object getResult(ResultGetter resultGetter) throws
SQLException {

       Array array = resultGetter.getArray();

       if (array == null) {

           return null;

       }

       else {

           List<ErrorObject> eoList = new ArrayList<ErrorObject>();

           Object[] objectArray = (Object[]) array.getArray();

           for (Object o: objectArray) {

               ErrorObject eo = (ErrorObject) o;

               eoList.add(eo);

           }

           return eoList;

       }

    }

 

 

I already have a straightforward JDBC example working with the same
objects, CodeRefObject and ErrorObject.   Why would one fail and other
not fail?

 

Thanks

Eric 


Mime
View raw message