JPA+ORACLE: Can't pass boolean param to my stored procedure

旧时模样 提交于 2021-02-10 05:42:05

问题


I can not pass boolean param to my stored procedure in Oracle. If I set value directly in the query text (mypackage.Test(?, false, ?, ?);) all work fine...

  • jdbc-driver: ojdbc6.jar
  • container: Tomcat 7.0.28
  • hibernate-core+hibernate-entitymanager: 4.1.6.Final
  • oracle: Oracle Database 11g Release 11.2.0.2.0 - 64bit Production

Here my realization:

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();

My persistance-unit:

<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>

Logs:

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 ...

What is wrong with my realization?

Thanks!

来源:https://stackoverflow.com/questions/14494696/jpaoracle-cant-pass-boolean-param-to-my-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!