2012-05-19 60 views
0

我冬眠的版本我使用的是3.2.5hibernate.connection.provider_class異常:​​無法實例連接提供商

這是我cfg.xml文件看起來像,我使用hibernate.connection.provider_class檢索連接:

<property name="hibernate.connection.provider_class">com.jdbc.ConnProvider</property> 
<property name="hibernate.jdbc.batch_size">30</property> 
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> 
<property name="hibernate.cache.use_query_cache">false</property> 
<property name="hibernate.cache.use_second_level_cache">false</property> 
<property name="hibernate.connection.release_mode">after_transaction</property> 
<property name="hibernate.connection.autocommit">true</property> 
<property name="hibernate.connection.pool_size">0</property> 
<property name="hibernate.current_session_context_class">thread</property>  
<property name="hibernate.show_sql">true</property> 
<property name="hibernate.hbm2ddl.auto">update</property>  

這是ConnProvider類:

package com.jdbc; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.SQLException; 
import java.util.Properties; 
import org.hibernate.HibernateException; 
import org.hibernate.connection.ConnectionProvider; 

/** 
* 
* @author gOMzY 
*/ 
class ConnProvider implements ConnectionProvider { 

    @Override 
    public Connection getConnection() throws SQLException { 
     Connection conn = null; 
     try{ 

      Class.forName("oracle.jdbc.OracleDriver"); 
      conn=DriverManager.getConnection("<url>","<username>","<pwd>"); 
      System.out.println("Connected!!!"); 
     }catch(Exception e){ 
      throw new UnsupportedOperationException("Not supported yet."); 
     } 
     return conn; 
    } 

    @Override 
    public void closeConnection(Connection cnctn) throws SQLException { 
     throw new UnsupportedOperationException("Not supported yet."); 
    } 

    @Override 
    public boolean supportsAggressiveRelease() { 
     return false; 
    } 

    @Override 
    public void close() throws HibernateException { 
     throw new UnsupportedOperationException("Not supported yet."); 
    } 

    @Override 
    public void configure(Properties prprts) throws HibernateException { 
     throw new UnsupportedOperationException("Not supported yet."); 
    } 

} 

例外我得到:

重度:無法實例連接提供商 java.lang.IllegalAccessException:類org.hibernate.connection.ConnectionProviderFactory不能與修飾符訪問類com.infy.jdbc.ConnProvider的成員「」在 sun.reflect.Reflection .ensureMemberAccess(未知來源) 在java.lang.Class.newInstance0(未知來源) 在java.lang.Class.newInstance(未知來源) 在org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:73) at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration。 java:1292) at com.infy.jdbc.HibernateStartup.main(HibernateStartup.java:19)

請建議如何解決此問題。

問候,

回答

1

請注意,您的連接提供商默認的知名度,也許它應該是公開的,而不是:

public ConnProvider implements ConnectionProvider { ... } 
+0

得到這個異常:信息:初始化連接提供商:com.infy.jdbc.ConnProvider java.lang.UnsupportedOperationException:尚不支持。 \t在com.infy.jdbc.ConnProvider.configure(ConnProvider.java:47) \t在org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) \t在org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider (ConnectionProviderFactory.java:56) \t在org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414) \t在org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62。 – user182944

+0

這是我的主方法:SessionFactory sessionFactory = new Configuration().configure(「trial.cfg.xml」)。buildSessionFactory(); \t \t \t session = sessionFactory.openSession(); \t \t \t tx = session.beginTransaction(); \t \t \t Login login =(Login)session.get(Login.class,new String(「Gautam」)); \t \t \t System.out.println(「Name:」+ login.getName()); \t \t \t System.out.println(「年齡:」+登錄。getAge()); \t \t \t tx.commit(); – user182944

+0

@ user182944:您的代碼拋出'UnsupportedOperationException'。 – axtavt

相關問題