Hibernate configuredSession factory:null

时间:2013-05-15 23:26:03

标签: hibernate c3p0

所有我在日志中收到以下消息:
2013-05-14 01:32:47,079} ABSOLUTE {INFO org.hibernate.cfg.Configuration} 1 {:2074 - HHH000041:已配置的SessionFactory:null

我的应用最终因为太多连接而失败了。我有一种令人难以忘怀的感觉,这些都是相关的。我已经读过这个了;在这个网站上,但我无法真正找到解决方案。这是我的SessionFactoryUtil和我的hibernate.cfg.xml的代码。任何指针都将非常感激。

public class SessionFactoryUtil {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

private static SessionFactory configureSessionFactory() 
        throws HibernateException {

    Configuration configuration = new Configuration();
    configuration.configure();
    serviceRegistry = new ServiceRegistryBuilder()
            .applySettings(configuration.getProperties())
            .buildServiceRegistry();

    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    return sessionFactory;
}


public static SessionFactory getInstance() {
    return configureSessionFactory();
    //return sessionFactory;
}

public Session getCurrentSession() {
    return sessionFactory.getCurrentSession();
}

public static void close() {
    if (sessionFactory != null) {
        sessionFactory.close();
        sessionFactory = null;
    }
}

}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">xxxxxxxx</property>
    <property name="hibernate.connection.url">jdbc:mysql://xxxxx.cvo0kkopzfhs.us-west-1.rds.amazonaws.com/homemoviezoo</property>
    <property name="hibernate.connection.username">xxxxx</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="log4jdbc.drivers">jdbc:log4jdbc:mysql://xxxxcvo0kkopzfhs.us-west-1.rds.amazonaws.com/homemoviezoo</property>
    <!-- configuration pool via c3p0-->
            <property name="c3p0.acquire_increment">1</property>
            <property name="c3p0.idle_test_period">800</property> <!-- seconds -->
            <property name="c3p0.max_size">20</property>
            <property name="c3p0.max_statements">20</property>
            <property name="c3p0.min_size">5</property>
            <property name="c3p0.timeout">1800</property> <!-- seconds -->
            <property name="c3p0.maxConnectionAge">1200</property>
            <property name="conneciton.provider_class">
                            org.hibernate.connection.C3P0ConnectionProvider</property>


    <property     name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.show_sql">true</property>
    <!--  <property name="hbm2ddl.auto">update</property>-->
    <mapping class="com.local.shared.School"/>
    <mapping class="com.local.shared.SchoolVideo"/>
    <mapping class="com.local.shared.Category"/>
    <mapping class="com.local.shared.Administrator"/>
</session-factory>




</hibernate-configuration>

1 个答案:

答案 0 :(得分:2)

Configured SessionFactory: null没问题。那是因为你在程序启动后初始化会话工厂。

我认为问题是<property name="conneciton.provider_class">中的错误输入,应该是<property name="connection.provider_class">