没有为statement + java.lang.ClassCastException的参数*找到TypeHandler:java.util.ArrayList与[Ljava.lang.Object;不兼容;

时间:2014-03-26 23:38:40

标签: java mybatis typehandler

存储过程规范:

TYPE RESOURCELIST IS TABLE OF VARCHAR2(7);
PROCEDURE save_prvdr_scope_group_xref
(
    p_region_id                IN    bg_prvdr_scope_group_xref.region_id%TYPE,
    p_revision_id              IN    bg_prvdr_scope_group_xref.revision_id%TYPE,
    p_bg_revision_id           IN    bg_prvdr_scope_group_xref.bg_revision_id%TYPE,
    p_classification_id        IN    bg_prvdr_scope_group_xref.classification_id%TYPE,
    p_facility_id              IN    bg_prvdr_scope_group_xref.facility_id%TYPE,
    p_provider_group_id        IN    bg_prvdr_scope_group_xref.provider_group_id%TYPE,
    p_resourceList             IN    RESOURCELIST,
    p_user_id                  IN    bg_prvdr_scope_group_xref.create_user_id%TYPE,
    p_ora_rowscn               IN    NUMBER,
    p_cur_out                  OUT   g_cursor

);

Mybatis映射看起来像:

<mapper namespace="BookingGuidelineProviderScopeXRef">

<parameterMap id="updateProviderScopeGroupXRefParameters" type="java.util.Map" >
    <parameter property="REGIONID" jdbcType="INTEGER" javaType="int" mode="IN"/>
    <parameter property="REVISIONID" jdbcType="INTEGER" javaType="int" mode="IN"/>
    <parameter property="BGREVISIONID" jdbcType="INTEGER" javaType="int" mode="IN"/>
    <parameter property="CLASSIFICATIONID" jdbcType="INTEGER" javaType="int" mode="IN"/>
    <parameter property="FACILITY" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
    <parameter property="PROVIDER_GROUP_ID" jdbcType="INTEGER" javaType="int" mode="IN"/>
    <parameter property="RESOURCES" jdbcType="ARRAY"  javaType="java.util.List" mode="IN"/>
    <parameter property="USERID" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN" />
    <parameter property="ORAROWSCN" jdbcType="BIGINT" javaType="long" mode="IN" />      
    <parameter property="cur_out" jdbcType="CURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="BookingGuidelinesErrorMapping.ErrorMapBookingGuidelines" />

</parameterMap>

<insert id="updateProviderScopeGroupXRef" parameterMap="updateProviderScopeGroupXRefParameters" statementType="CALLABLE">
    {call PKG_BG_PRVDR_SCOPE_GROUP_XREF.save_prvdr_scope_group_xref (?,?,?,?,?,?,?,?,?,?)}
</insert>   
</mapper>

例外:

org.apache.ibatis.exceptions.PersistenceException:    ###查询数据库时出错。原因:org.apache.ibatis.executor.ExecutorException:
    没有为声明BookingGuidelineProviderScopeXRef.updateProviderScopeGroupXRef的参数资源找到TypeHandler    ###错误可能涉及BookingGuidelineProviderScopeXRef.updateProviderScopeGroupXRefParameters    ###设置参数时发生错误    ###原因:org.apache.ibatis.executor.ExecutorException:没有为声明BookingGuidelineProviderScopeXRef.updateProviderScopeGroupXRef的参数资源找到TypeHandler

我对mybatis很新。 任何有助于理解TypeHandler及其映射和实现的链接或示例都将受到高度赞赏。

基本上寻找一种解决方案,将mybatis中的字符串数组传递给oracle存储过程。

我也尝试添加以下内容:

public class ArrayTypeHandler implements TypeHandler<Object> {

public Object getResult(ResultSet resultSet, String columnName) throws SQLException {
    return resultSet.getObject(columnName);
}

public Object getResult(CallableStatement statement, int i)
        throws SQLException {
    return statement.getArray(i).getArray();

}

public void setParameter(PreparedStatement ps, int i, Object param,
        JdbcType jdbctype) throws SQLException {
    if (param == null) {
        ps.setNull(i, Types.ARRAY);
    } else {
        Connection conn = ps.getConnection();
        Array loc = conn.createArrayOf("RESOURCELIST", (Object[]) param);
        ps.setArray(i, loc);
    }

}

}

org.apache.ibatis.exceptions.PersistenceException:

查询数据库时出错。原因:java.lang.ClassCastException:java.util.ArrayList与[Ljava.lang.Object;

不兼容

该错误可能涉及BookingGuidelineProviderScopeXRef.updateProviderScopeGroupXRefParameters

设置参数

时发生错误

原因:java.lang.ClassCastException:java.util.ArrayList与[Ljava.lang.Object;

不兼容
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:81)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:73)
at org.kp.cccs.sysadmin.booking.dao.BookingGuidelineProviderScopeGroupXRefBuilder.updateProviderScopeGroupXRef(BookingGuidelineProviderScopeGroupXRefBuilder.java:62)
at org.kp.cccs.sysadmin.booking.junit.TestProviderScopeGroupBuilderXRef.testUpdateProviderScopeGroupXRef(TestProviderScopeGroupBuilderXRef.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

引起:java.lang.ClassCastException:java.util.ArrayList与[Ljava.lang.Object;不兼容;     at org.kp.cccs.sysadmin.booking.model.dto.util.ArrayTypeHandler.setParameter(ArrayTypeHandler.java:39)     在org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:73)     at org.apache.ibatis.executor.statement.CallableStatementHandler.parameterize(CallableStatementHandler.java:64)     在org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:43)     在org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:56)     在org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:40)     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:243)     在org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:117)     在org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:72)     在org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:79)     ......还有22个 谢谢,

0 个答案:

没有答案