ClassCastException when using pooled oracle connections

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ClassCastException when using pooled oracle connections

sarah@frenchfrieswithpepper.co
I'm hoping to upgrade to hibernate spatial 1.1 but initial results are giving me a ClassCastException on line 51 of OracleJDBCTypeFactory.

java.lang.ClassCastException: org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
at oracle.sql.STRUCT.<init>(STRUCT.java:138)
at org.hibernatespatial.oracle.OracleJDBCTypeFactory.createStruct(OracleJDBCTypeFactory.java:51)
at org.hibernatespatial.oracle.SDOGeometry.store(SDOGeometry.java:154)
at org.hibernatespatial.oracle.SDOGeometryType.conv2DBGeometry(SDOGeometryType.java:82)
...

I have a custom ConnectionFinder which is being called to return the "oracleConnection" in OracleJDBCTypeFactory.createStruct, but since the oracleConnection is not used to create the STRUCT (the initial method argument conn is used instead), I am getting this ClassCastException.

The only thing I can think to do is try to override the createStruct method, but I'm hoping there is a more elegant solution.

Thanks,
Sarah

P.S.  My ConnectionFinder implementation...

import java.sql.Connection;
import oracle.jdbc.driver.OracleConnection;
import org.apache.commons.dbcp.DelegatingConnection;
import org.apache.commons.dbcp.PoolableConnection;
import org.hibernatespatial.helper.FinderException;
import org.hibernatespatial.oracle.ConnectionFinder;
public class OracleDbcpConnectionFinder implements ConnectionFinder {
@Override
public OracleConnection find(Connection conn) throws FinderException {
DelegatingConnection delegatingConnection = (org.apache.commons.dbcp.DelegatingConnection)conn;
PoolableConnection poolableConnection = (PoolableConnection) delegatingConnection.getDelegate();
Connection oracleConnection = poolableConnection.getDelegate();
return (OracleConnection) oracleConnection;
}
}

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: ClassCastException when using pooled oracle connections

Karel Maesen
Administrator
Hi Sarah,


That is a definitely a bug - oracleConnection should have been used in
line 51.

I created an issue for it, and will fix this soon. A fix will appear in
trunk by the end of next week. I'll probably release it a bit later.

Thank you for the detailed report.

Regards,

Karel



> I'm hoping to upgrade to hibernate spatial 1.1 but initial results are
> giving me a ClassCastException on line 51 of OracleJDBCTypeFactory.
>
> java.lang.ClassCastException:
> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
> cannot
> be cast to oracle.jdbc.OracleConnection
> at oracle.sql.STRUCT.<init>(STRUCT.java:138)
> at
> org.hibernatespatial.oracle.OracleJDBCTypeFactory.createStruct(OracleJDBCTypeFactory.java:51)
> at org.hibernatespatial.oracle.SDOGeometry.store(SDOGeometry.java:154)
> at
> org.hibernatespatial.oracle.SDOGeometryType.conv2DBGeometry(SDOGeometryType.java:82)
> ...
>
> I have a custom ConnectionFinder which is being called to return the
> "oracleConnection" in OracleJDBCTypeFactory.createStruct, but since the
> oracleConnection is not used to create the STRUCT (the initial method
> argument conn is used instead), I am getting this ClassCastException.
>
> The only thing I can think to do is try to override the createStruct
> method,
> but I'm hoping there is a more elegant solution.
>
> Thanks,
> Sarah
>
> P.S.  My ConnectionFinder implementation...
>
> import java.sql.Connection;
> import oracle.jdbc.driver.OracleConnection;
> import org.apache.commons.dbcp.DelegatingConnection;
> import org.apache.commons.dbcp.PoolableConnection;
> import org.hibernatespatial.helper.FinderException;
> import org.hibernatespatial.oracle.ConnectionFinder;
> public class OracleDbcpConnectionFinder implements ConnectionFinder {
> @Override
> public OracleConnection find(Connection conn) throws FinderException {
> DelegatingConnection delegatingConnection =
> (org.apache.commons.dbcp.DelegatingConnection)conn;
> PoolableConnection poolableConnection = (PoolableConnection)
> delegatingConnection.getDelegate();
> Connection oracleConnection = poolableConnection.getDelegate();
> return (OracleConnection) oracleConnection;
> }
> }
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: ClassCastException when using pooled oracle connections

Karel Maesen
Administrator
In reply to this post by sarah@frenchfrieswithpepper.co
Hi Sarah,

This issue is now fixed in trunk (version 1.1.1-SNAPSHOT). I deployed the snapshot builds to the HS maven repository.

Regards,

Karel

On 08 Jun 2011, at 18:39, Sarah Haskins wrote:

> I'm hoping to upgrade to hibernate spatial 1.1 but initial results are giving me a ClassCastException on line 51 of OracleJDBCTypeFactory.
>
> java.lang.ClassCastException: org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
> at oracle.sql.STRUCT.<init>(STRUCT.java:138)
> at org.hibernatespatial.oracle.OracleJDBCTypeFactory.createStruct(OracleJDBCTypeFactory.java:51)
> at org.hibernatespatial.oracle.SDOGeometry.store(SDOGeometry.java:154)
> at org.hibernatespatial.oracle.SDOGeometryType.conv2DBGeometry(SDOGeometryType.java:82)
> ...
>
> I have a custom ConnectionFinder which is being called to return the "oracleConnection" in OracleJDBCTypeFactory.createStruct, but since the oracleConnection is not used to create the STRUCT (the initial method argument conn is used instead), I am getting this ClassCastException.
>
> The only thing I can think to do is try to override the createStruct method, but I'm hoping there is a more elegant solution.
>
> Thanks,
> Sarah
>
> P.S.  My ConnectionFinder implementation...
>
> import java.sql.Connection;
> import oracle.jdbc.driver.OracleConnection;
> import org.apache.commons.dbcp.DelegatingConnection;
> import org.apache.commons.dbcp.PoolableConnection;
> import org.hibernatespatial.helper.FinderException;
> import org.hibernatespatial.oracle.ConnectionFinder;
> public class OracleDbcpConnectionFinder implements ConnectionFinder {
> @Override
> public OracleConnection find(Connection conn) throws FinderException {
> DelegatingConnection delegatingConnection = (org.apache.commons.dbcp.DelegatingConnection)conn;
> PoolableConnection poolableConnection = (PoolableConnection) delegatingConnection.getDelegate();
> Connection oracleConnection = poolableConnection.getDelegate();
> return (OracleConnection) oracleConnection;
> }
> }
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users