Getting a handle to native Oracle Connection in Hibernate 4 to run a stored proc

前端 未结 2 1496
执笔经年
执笔经年 2020-12-11 14:24

This is a follow-up to Executing native query with Hibernate 4.1

I\'ve tried the options in the listed answer but we get errors and are unable to unwrap the proxied

相关标签:
2条回答
  • 2020-12-11 14:45

    Option 2 code works correctly.

    ie.

    OracleConnection oracleConnection = connection.unwrap( OracleConnection.class );

    The problem was we had 2 versions of ojbc.jar - one as a Jboss module and one within the EAR, hence the ClassCastException.

    As mentioned in the comments, this code also works

    oracle.jdbc.driver.OracleConnection oc = (oracle.jdbc.driver.OracleConnection) connection.getMetaData().getConnection();

    0 讨论(0)
  • 2020-12-11 14:55

    Try the following

    I had encountered the same issue. We were using spring and it has a class called NativeJdbcExtractor. It has many implementations and the following one works for TomCat. There is a specific implementation for Jboss called the JBossNativeJdbcExtractor

    <bean id="jdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"></bean>
    

    In your DAO you can inject the bean and use the following method

    protected NativeJdbcExtractor jdbcExtractor;
    Connection conn=jdbcExtractor.getNativeConnection(oracleConnection);
    
    0 讨论(0)
提交回复
热议问题