2013-10-10 13 views
1

我有以下結構:展開NewProxyConnection和從的getConnection NewProxyConnection

  1. 與Hibernate 4.0.1的層,使用作爲C3P0連接池。
  2. 我沒有配置數據源,我用數據源的動態配置喜歡它:

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("persitenceUnit", createMap(ds)); 
    

「DS」是一個對象與我的數據庫屬性,如用戶名,密碼,網址, ...

  1. 我得到的EntityManager這樣:

    EntityManager em = emf.createEntityManager(); 
    
  2. 我嘗試獲取連接這樣:

    EntityManagerImpl entityManagerImpl = (EntityManagerImpl)em; 
    SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl)entityManagerImpl.getSession().getSessionFactory(); 
    Connection con = sessionFactoryImpl.getConnectionProvider().getConnection(); 
    

但是,con是一個NewProxyConnection實例。我需要執行一個返回ORADATA和con.prepareCall(sqlToProcedure)返回NewProxyCallableStatment沒有有getOraData,即一個過程,這個代碼不工作:

OracleCallableStatment ocs = (OracleCallableStatment)con.prepareCall('{call stp_test(?)}'); 
ocs.excute();  
TestObjectodf to = ocs.getOraDATA(1, TestObject.getOraDataFactory());  

的錯誤

OracleCallableStatment ocs = (OracleCallableStatment)con.prepareCall('{call stp_test(?)}'); 

發生了,我嘗試:

NewProxyConnection npCon = sessionFactoryImpl.getConnectionProvider().getConnection(); 
Connection con = npCon.unwrap(Connection.class); 

但是不行。

回答

0

解包()方法將工作,如果升級到最新版本c3p0-0.9.5 prerelease。 unwrap()是一個JDBC4方法,由c3p0和c3p0-0.9.5支持。由於您需要一個OracleCallableStatement,因此您可能需要調用CallableStatement的unwrap()方法,而不是Connection的unwrap()方法。

或者(和一點更安全),與庫中幾乎所有的版本,你可以使用C3P0的原始陳述的操作。 See the docs