任何有兴趣,我已经通过调用一个服务中的下列解决了这个问题:
/**
* 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
}
我还补充说:
import org.hibernate.jdbc.Work
和
def sessionFactory
注入sessionFactory bean。
此代码包含在没有dataSource.groovy文件的插件中,并且在我的项目中运行良好。