2

我无法将布尔参数传递给我在 Oracle 中的存储过程。如果我直接在查询文本中设置值 (mypackage.Test(?, false, ?, ?);) 一切正常......

  • jdbc 驱动程序:ojdbc6.jar
  • 容器:Tomcat 7.0.28
  • 休眠核心+休眠实体管理器:4.1.6.Final
  • oracle:Oracle 数据库 11g 版本 11.2.0.2.0 - 64 位生产

这是我的实现:

EntityManager em = defaultFactory.createEntityManager();
em.createNativeQuery("BEGIN mypackage.Test(?, ?, ?, ?); END;")//
    .setParameter(1, factId)//
    .setParameter(2, false)//
    .setParameter(3, auth.getDt())//
    .setParameter(4, auth.getName())//
.executeUpdate();

我的持久性单元:

<persistence-unit name="unit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>java:/comp/env/jdbc/db</non-jta-data-source>
        <properties>
        <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/> 
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /> 
        <property name="hibernate.hbm2ddl.auto" value="validate" /> 
        <property name="hibernate.connection.characterEncoding" value="UTF-8" /> 
        <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
    </properties>
</persistence-unit>

日志:

2013-01-24 11:28:44,582 DEBUG JdbcTransaction (71) - disabling autocommit
 2013-01-24 11:28:44,633 TRACE QueryPlanCache (196) - Unable to locate native-sql query plan in cache; generating (BEGIN 2013-01-24 11:28:44,582 DEBUG JdbcTransaction (71) - disabling autocommit
 2013-01-24 11:28:44,633 TRACE QueryPlanCache (196) - Unable to locate native-sql query plan in cache; generating (BEGIN mypackage.Test(?, ?, ?, ?); END;)
 2013-01-24 11:28:44,644 TRACE SQLCustomQuery (85) - Starting processing of sql query [BEGIN Collection_Fact_IUD.Del(?, ?, ?, ?); END;]
 2013-01-24 11:28:44,669 TRACE ConnectionProxyHandler (110) - Handling invocation of connection method [prepareStatement]
 2013-01-24 11:28:44,669 DEBUG SqlStatementLogger (104) - BEGIN mypackage.Test(?, ?, ?, ?); END;
 2013-01-24 11:28:44,670 TRACE JdbcResourceRegistryImpl (65) - Registering statement [org.hibernate.engine.jdbc.internal.proxy.PreparedStatementProxyHandler@41801d[valid=true]]
 2013-01-24 11:28:44,670 TRACE BasicBinder (83) - binding parameter [1] as [BIGINT] - 68593
 2013-01-24 11:28:44,670 TRACE AbstractStatementProxyHandler (88) - Handling invocation of statement method [setLong]
 2013-01-24 11:28:44,670 TRACE PreparedStatementProxyHandler (75) - Binding via setLong: [1, 68593]
 2013-01-24 11:28:44,672 TRACE BasicBinder (83) - binding parameter [2] as [BIT] - false
 2013-01-24 11:28:44,673 TRACE AbstractStatementProxyHandler (88) - Handling invocation of statement method [setBoolean]
 2013-01-24 11:28:44,673 TRACE PreparedStatementProxyHandler (75) - Binding via setBoolean: [2, false]
 2013-01-24 11:28:44,673 TRACE BasicBinder (83) - binding parameter [3] as [TIMESTAMP] - 2013-01-24 11:28:44.631
 2013-01-24 11:28:44,673 TRACE AbstractStatementProxyHandler (88) - Handling invocation of statement method [setTimestamp]
 2013-01-24 11:28:44,673 TRACE PreparedStatementProxyHandler (75) - Binding via setTimestamp: [3, 2013-01-24 11:28:44.631]
 2013-01-24 11:28:44,674 TRACE BasicBinder (83) - binding parameter [4] as [VARCHAR] - unknown
 2013-01-24 11:28:44,674 TRACE AbstractStatementProxyHandler (88) - Handling invocation of statement method [setString]
 2013-01-24 11:28:44,674 TRACE PreparedStatementProxyHandler (75) - Binding via setString: [4, unknown]
 2013-01-24 11:28:44,675 TRACE AbstractStatementProxyHandler (88) - Handling invocation of statement method [executeUpdate]
 2013-01-24 11:28:44,691 DEBUG SqlExceptionHelper (139) - ORA-06550: Строка 1, столбец 7:
PLS-00306: ошибочно число или типы аргументов при обращении к 'Test'
ORA-06550: Строка 1, столбец 7:
PL/SQL: Statement ignored
 [n/a]
 java.sql.SQLException: ORA-06550: Строка 1, столбец 7:
PLS-00306: ошибочно число или типы аргументов при обращении к 'Test'
ORA-06550: Строка 1, столбец 7:
PL/SQL: Statement ignored

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
    at ...

我的认识有什么问题?

谢谢!

4

0 回答 0