您好我正在使用带有 Fedora 17 版的 Linux 操作系统,我的 Hibernate 配置文件如下
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/Test
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
root
</property>
<property name="show_sql">false</property>
<property name="format_sql">false</property>
<property name="use_sql_comments">false</property>
<property name="hibernate.connection.pool_size">40</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_periods">3000</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
</hibernate-configuration>
</session-factory>
在服务器中使用此配置,我经常收到以下错误
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]] with root cause
org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:126)
at org.hibernate.internal.SessionFactoryImpl.getStatisticsImplementor(SessionFactoryImpl.java:1468)
at org.hibernate.internal.SessionFactoryImpl.getStatistics(SessionFactoryImpl.java:1464)
at org.hibernate.internal.SessionImpl.close(SessionImpl.java:346)
我的连接代码如下,
public class DBConnection{
private static SessionFactory factory;
private static DBConnection singleton = new DBConnection();
// private static final SessionFactory sessionFactory;
private DBConnection(){ }
/* Static 'instance' method */
public static DBConnection getInstance( ) {
return singleton;
}
public static SessionFactory getSessionFactory(){
if (factory == null ) {
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}
return factory;
}
public static Session getSession()
{
return getSessionFactory().openSession();
}
// Call this during shutdown
public static void close() {
factory.close();
factory=null;
}
由于这个原因,我的应用程序变慢了,我可以在 MySQL 中看到睡眠查询。
如何解决这个问题?在这种环境下如何配置?非常感谢任何帮助。
谢谢!!