[英]Executing native query with Hibernate 4.1
I'm using Hibernate with C3P0 connection pool. 我在C3P0连接池中使用Hibernate。 In Hibernate 3 I could get access to wrapped C3P0ProxyConnection through
BorrowedConnectionProxy
and then perform rawConnectionOperation
. 在Hibernate 3中,我可以通过
BorrowedConnectionProxy
访问包装的C3P0ProxyConnection,然后执行rawConnectionOperation
。 From what I see BorrowedConnectionProxy
is not a part of Hibernate 4.1 anymore. 从我看来,
BorrowedConnectionProxy
不再是Hibernate 4.1的一部分。
Is it any way I can run vendor specific queries ? 我可以通过任何方式运行供应商特定的查询吗? (An instance of proxy connection inside
Work.execute
does not work for me, I need to execute Oracle stored procedure that takes collection of custom object type). (
Work.execute
中的代理连接实例对我不起作用,我需要执行需要存储自定义对象类型的Oracle存储过程)。
Thank you . 谢谢 。
You can get access to the unproxied Connection in Work by calling: 您可以通过以下方式访问Work中未代理的连接:
public void execute(Connection connection) throws SQLException {
Connection unproxiedConnection = connection.unwrap( Connection.class );
...
}
That form leverages the JDBC 4 unwrap method, we simply delegate that to the underlying connection. 这种形式利用了JDBC 4的unwrap方法,我们仅将其委托给基础连接。 Or if you specifically need an OracleConnection:
或者,如果您特别需要OracleConnection:
public void execute(Connection connection) throws SQLException {
OracleConnection oracleConnection = connection.unwrap( OracleConnection.class );
...
}
You could also use: 您还可以使用:
public void execute(Connection connection) throws SQLException {
Connection unproxiedConnection = ( (JdbcWrapper<Connection>) connection ).getWrappedObject();
...
}
I have gone back and forth in terms of contemplating allowing the Work to signify that it wants an unproxied Connection, but given the availability of Connection#unwrap I am not so sure there is an real benefit. 考虑到允许工作表明它想要一个未经代理的连接,我来回走了,但是鉴于Connection#unwrap的可用性,我不确定是否有真正的好处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.