Closed FrenkelS closed 1 year ago
Why not writing your own implementation and use that? I had the same problem concerning HikariCP. Here is my solution:
First I wrote a ConnectionFinder:
import java.sql.Connection;
import java.sql.SQLException;
import org.geolatte.geom.codec.db.oracle.ConnectionFinder;
import org.geolatte.geom.codec.db.oracle.DefaultConnectionFinder;
import com.zaxxer.hikari.pool.HikariProxyConnection;
import oracle.jdbc.driver.OracleConnection;
/**
* Implementation of {@link ConnectionFinder} needed by hibernate spatial on ORACLE only.
*
* @author Christian Marsch
*/
public class HikariConnectionFinder extends DefaultConnectionFinder {
/** */
private static final long serialVersionUID = 6225703364781158873L;
/**
*
*/
public HikariConnectionFinder() {
}
@Override
public Connection find(final Connection con) {
if (HikariProxyConnection.class.isInstance(con)) {
try {
return HikariProxyConnection.class.cast(con).unwrap(OracleConnection.class);
} catch (SQLException e) {
throw new RuntimeException(e);
}
} else {
return super.find(con);
}
}
}
Important is the NoArgs Constructor. In Hibernate configuration I added it as a property:
hibernate.spatial.connection_finder=package.of.HikariConnectionFinder.class
I'm using Quarkus. To use your own implementation of a ConnectionFinder in Quarkus you need to add to your application.properties:
quarkus.hibernate-orm.unsupported-properties."hibernate.spatial.connection_finder" = package.of.MyConnectionFinder
Because you're now using unsupported properties, you get a big warning from Quarkus every time you start up your application.
I'm using Quarkus. To use your own implementation of a ConnectionFinder in Quarkus you need to add to your application.properties:
quarkus.hibernate-orm.unsupported-properties."hibernate.spatial.connection_finder" = package.of.MyConnectionFinder
Because you're now using unsupported properties, you get a big warning from Quarkus every time you start up your application.
I see. Did not know that. Thx for explaining me this.
The code is sufficiently general and doesn't introduce additional dependencies so I have no problem merging this.
Thanks for the PR!
In my application I have a
io.agroal.pool.wrapper.ConnectionWrapper
which wraps an Oracle connection. TheDefaultConnectionFinder
can't find the Oracle connection because the wrapper doesn't have a getter that returns the Oracle connection. It does however have theunwrap()
method which return the Oracle connection. So try to use that before falling back on reflection.