【问题标题】:How to get oracle connection from hibernate connection如何从休眠连接获取oracle连接
【发布时间】:2021-05-12 18:47:32
【问题描述】:

我正在尝试从休眠中获取 oracle 连接。下面是我正在使用的代码。

server.xml

<library id="jdbcDriverFiles">
    <fileset dir="libraries" includes="ojdbc7.jar" />
</library>

<dataSource id="x" jndiName="jndisce"
    statementCacheSize="20" type="javax.sql.DataSource">
    <containerAuthData password="Pwd" user="User" />
    <jdbcDriver javax.sql.DataSource="oracle.jdbc.pool.OracleDataSource" libraryRef="jdbcDriverFiles" />
    <connectionManager agedTimeout="600"
        connectionTimeout="180" maxIdleTime="1800" maxPoolSize="70"
        minPoolSize="1" purgePolicy="EntirePool" reapTime="180" />
    <properties.oracle
        URL="url"
        password="Pwd" portNumber="123" serverName="server"
        user="User" />
</dataSource>   

<webApplication id="cm" location="cm.war"
    name="cm">
    <classloader commonLibraryRef="jdbcDriverFiles" />
</webApplication>

InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jndisce");
Connection conn = ds.getConnection();
OracleConnection con = conn.unwrap(OracleConnection.class);

以下是我遇到的错误。

java.sql.SQLException: DSRA9122E: com.ibm.ws.rsadapter.jdbc.v41.WSJdbc41Connection@7acaddcd does not 
wrap any objects of type oracle.jdbc.OracleConnection.

【问题讨论】:

    标签: oracle hibernate


    【解决方案1】:

    这与 Hibernate 无关,您甚至没有在这里使用 Hibernate API。您正试图从 IBM 数据源连接中解开 OracleConnection,但显然它不允许您这样做。根据以下文章,这可能是由于类加载器问题:how to unwrap PostgreSQL connection from the IBM WSJdbc41Connection

    【讨论】:

    • 感谢您的回复。你能帮我解决上述问题吗?我正在使用 WAS 服务器。如何从 WAS 获取 oracle 连接。
    • 您是否阅读了我在回答中写的问题的答案?您是否尝试在dataSource 元素中设置enableConnectionCasting 属性?您确定 cm.war 不包含 jdbc 驱动程序吗?
    猜你喜欢
    • 1970-01-01
    • 2012-03-17
    • 2012-04-21
    • 2015-03-04
    • 1970-01-01
    • 2016-07-15
    • 2011-01-05
    • 2016-09-07
    相关资源
    最近更新 更多