Search code examples
javaoracle-databaseoracle10gibatis

Ibatis Ref Curosr issue with Oracle


I'm using Java and Ibatis to call a stored procedure on on oracle database. I seem to be having an issue setting up with parameters.

The store procedure looks like the following:

PROCEDURE Get_Semployees_By_Clt_ID
    (
        client_id IN HRIS.SEMPLOYEES.SEE_CLT_ID%TYPE,    
        ref_cursor OUT SYS_REFCURSOR
    );

My Ibatis SqlMap:

<sqlMap namespace="Foo">


<resultMap id="employee-map" class="MyFoo">  
   <result property="foo1" column="foo1"/>  
   <result property="foo2" column="foo2"/>  
</resultMap>   

<parameterMap id="clientEmployeesParms" class="java.util.Map" >
    <parameter property="in1" jdbcType="INTEGER" javaType="java.lang.Integer" mode="IN"/>
    <parameter property="output1" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet"    mode="OUT" />
</parameterMap>

    <procedure id="clientEmployees" parameterMap="clientEmployeesParms" resultMap="employee-map">
    { call Package.Get_Clt_ID(?,?) }
    </procedure>

</sqlMap>

My Java:

resource = "SqlMapConfig.xml";
reader = Resources.getResourceAsReader (resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
Map map = new HashMap();
map.put("in1", new Integer(23));
list = sqlMap.queryForList("Foo.clientEmployees", map);

Error:

--- The error occurred while applying a parameter map.  
--- Check the Employee.clientEmployeesParms.  
--- Check the output parameters (retrieval of output parameters failed).  
--- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
 at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
 at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
 at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
 at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
 at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
 at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
 at com.apache.struts.employee.model.IbatisStoredProcedure.main(IbatisStoredProcedure.java:30)

Solution

  • Peter. Are you going through bootcamp? (I work where you work, possibly in the same building. I'll shoot you an email tomorrow.)

    I think the problem is because the resultMap needs to have the property names be the same as what is being returned by the procedure. In this case, whatever is being selected into the cursor.