如何使用REF_CURSOR正确执行@NamedStoredProcedureQuery

时间:2019-02-08 15:45:12

标签: java hibernate stored-procedures oracle12c

我想在Oracle DB上执行存储过程。我已经阅读了尽可能多的教程,博客等,但是仍然无法解决。

当我尝试执行存储过程时,我收到消息:

Caused by: org.hibernate.exception.GenericJDBCException: Error registering REF_CURSOR parameter [P_RETURN_VALUE]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.cursor.internal.StandardRefCursorSupport.registerRefCursorParameter(StandardRefCursorSupport.java:72)
at org.hibernate.query.procedure.internal.ProcedureParameterImpl.prepare(ProcedureParameterImpl.java:283)
at org.hibernate.procedure.internal.ProcedureCallImpl$3.accept(ProcedureCallImpl.java:397)
at org.hibernate.procedure.internal.ProcedureCallImpl$3.accept(ProcedureCallImpl.java:390)
at org.hibernate.query.procedure.internal.ProcedureParameterMetadata.visitRegistrations(ProcedureParameterMetadata.java:186)
at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:389)
at org.hibernate.procedure.internal.ProcedureCallImpl.getOutputs(ProcedureCallImpl.java:352)
at org.hibernate.procedure.internal.ProcedureCallImpl.outputs(ProcedureCallImpl.java:632)
at org.hibernate.procedure.internal.ProcedureCallImpl.execute(ProcedureCallImpl.java:615)
... 88 more
Caused by: java.sql.SQLException: Ungültiger Spaltentyp: 2012
at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3978)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:140)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:2401)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:2307)
at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1250)
at weblogic.jdbc.wrapper.CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper.registerOutParameter(Unknown Source)
at org.hibernate.engine.jdbc.cursor.internal.StandardRefCursorSupport.registerRefCursorParameter(StandardRefCursorSupport.java:69)
... 96 more

环境:

  • WebLogic 12.2.1.3.0
  • Java EE 7
  • 休眠5.4.1

服务:

protected void openTransaktion(ArasBenutzer arasBenutzer, String procedureName){

    try {
        StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("TransaktionsProcedureCall.openTransaktion");
        query.setParameter("P_ABP_KENNUNG", arasBenutzer.getKennung());
        query.execute();
        Object obj = query.getResultList();
    } catch (Exception e) {
        throw new ArasException(String.format(propertiesHelper.getMessage("openTransaktion.fehler"), procedureName), e.getMessage(), ExceptionUtils.getStackTrace(e));
    }
}

TransaktionProcedureCall:

@SuppressWarnings("serial")
@Entity
@NamedStoredProcedureQueries({
    @NamedStoredProcedureQuery(name = "TransaktionsProcedureCall.openTransaktion", procedureName = "PCK_0212.PPC_OPEN_TRANSACTION", resultClasses = Object.class, parameters = {
            @StoredProcedureParameter(name="P_RETURN_VALUE, mode=ParameterMode.REF_CURSOR, type=void.class),
            @StoredProcedureParameter(name="P_ABP_KENNUNG", mode=ParameterMode.IN, type=String.class)
    })
})
public class TransaktionsProcedureCall extends ProcedureCallAbstract {

}

persistence.xml:

<persistence-unit name="arasPersistenceUnit" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>ArasDataSource</jta-data-source>
    <properties>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle12cDialect" />
    </properties>
</persistence-unit>

0 个答案:

没有答案