0

I have upgraded my project from Grails 2.2.3 to 2.4.2 using hibernate 4. (4.3.5.4)

There is a service in this project that uses Oracle spatial queries and processes to generate results.

Converting an Oracle JGeometry object to an Oracle STRUCT requires the database connection object to work: STRUCT obj = JGeometry(geom, connection)

How can I get the java.sql.Connection object from Hibernate 4?

Graham H
  • 125
  • 12

1 Answers1

0

For anyone interested, I have resolved the problem by calling the following from within a service:

    /**
 * createConnection creates a database connection using the java.sql.DriverManager
 * The parameters used to make the connection are taken from the current session
 * @return java.sql.Connection object
 */
Connection createConnection(){

    oracle.jdbc.OracleConnection cnx = null
    try {
        sessionFactory?.currentSession?.doWork new Work(){
            void execute(Connection c){
                //convert the com.sun.proxy.$Proxy<nn> connection to Oracle
                cnx = c.unwrap(oracle.jdbc.OracleConnection.class)
            }
        }

        return cnx

    }
    catch (SQLException sqle){
        RIMS.ConnectionService.log.error "Error in createConnection:  ${sqle.message}"
    }
    return null
}

I also added:

import org.hibernate.jdbc.Work

and

def sessionFactory

to inject the sessionFactory bean.

This code is contained within a plugin without a dataSource.groovy file and is working well in my project.

Graham H
  • 125
  • 12