hibernate.connection.provider_class异常:​​无法实例化连接提供程序

时间:2012-05-19 18:24:13

标签: hibernate hibernate-mapping hibernate-criteria

我正在使用的休眠版本是3.2.5

这是我的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的成员         at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)         在java.lang.Class.newInstance0(未知来源)         在java.lang.Class.newInstance(未知来源)         在org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:73)         在org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)         在org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)         在org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)         在org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)         在com.infy.jdbc.HibernateStartup.main(HibernateStartup.java:19)

请建议如何解决此问题。

此致

1 个答案:

答案 0 :(得分:1)

请注意,您的连接提供商具有默认可见性,可能应该公开:

public ConnProvider implements ConnectionProvider { ... }