2012-08-10 103 views
2

我使用hibernate4和彈簧3和JSF2.0 注射用我的註釋 我搜索這個例外在谷歌,但沒有找到任何合適的解決方案 在這裏,我已經發布了我的日誌,應用程序上下文和DAO實現org.springframework.orm.hibernate4.HibernateSystemException:請求的未知服務[org.hibernate.stat.spi.StatisticsImplementor];

Here is my logs 
> BlockquoteHibernate: select employee0_.empid as empid0_, employee0_.emailId as emailId0_, employee0_.mobileNo as mobileNo0_, employee0_.password as password0_, employee0_.skypeID as skypeID0_, employee0_.userName as userName0_ from employee employee0_ where employee0_.userName=? 
Aug 10, 2012 5:00:28 PM javax.faces.event.MethodExpressionActionListener processAction 
SEVERE: Received 'org.springframework.orm.hibernate4.HibernateSystemException' when invoking action listener '#{loginBacking.empLogin}' for component 'j_idt16' 
Aug 10, 2012 5:00:28 PM javax.faces.event.MethodExpressionActionListener processAction 
SEVERE: org.springframework.orm.hibernate4.HibernateSystemException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]; nested exception is org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor] 
    at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:206) 
    at org.springframework.orm.hibernate4.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:606) 
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:507) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:845) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:411) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:114) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy17.empLogin_Service(Unknown Source) 
    at com.airwatch.device.backingbeans.LoginBacking.empLogin(LoginBacking.java:66) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.apache.el.parser.AstValue.invoke(AstValue.java:264) 
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149) 
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:84) 
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:296) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: 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:1710) 
    at org.hibernate.internal.SessionFactoryImpl.getStatistics(SessionFactoryImpl.java:1706) 
    at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.afterTransaction(TransactionCoordinatorImpl.java:140) 
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.afterTransactionCompletion(JdbcTransaction.java:138) 
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:214) 
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:500) 
    ... 40 more 

Aug 10, 2012 5:00:28 PM com.sun.faces.context.ExceptionHandlerImpl log 
SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt10:j_idt16, Message=org.springframework.orm.hibernate4.HibernateSystemException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]; nested exception is org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor] 
Aug 10, 2012 5:00:28 PM com.sun.faces.context.ExceptionHandlerImpl log 
SEVERE: org.springframework.orm.hibernate4.HibernateSystemException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]; nested exception is org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor] 
javax.faces.event.AbortProcessingException: org.springframework.orm.hibernate4.HibernateSystemException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]; nested exception is org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor] 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:178) 
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:84) 
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:296) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: org.springframework.orm.hibernate4.HibernateSystemException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]; nested exception is org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor] 
    at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:206) 
    at org.springframework.orm.hibernate4.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:606) 
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:507) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:845) 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:411) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:114) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy17.empLogin_Service(Unknown Source) 
    at com.airwatch.device.backingbeans.LoginBacking.empLogin(LoginBacking.java:66) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.apache.el.parser.AstValue.invoke(AstValue.java:264) 
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149) 
    ... 25 more 
Caused by: 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:1710) 
    at org.hibernate.internal.SessionFactoryImpl.getStatistics(SessionFactoryImpl.java:1706) 
    at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.afterTransaction(TransactionCoordinatorImpl.java:140) 
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.afterTransactionCompletion(JdbcTransaction.java:138) 
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:214) 
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:500) 
    ... 40 more 

> Blockquote> 

,這裏是我的應用程序上下文

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee-3.1.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:annotation-config/> 
    <!-- .....................................Data Base Related Config............................. --> 
    <bean id="DataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName"> 
      <value>com.mysql.jdbc.Driver</value> 
     </property> 
     <property name="url"> 
      <value>jdbc:mysql://localhost:3306/test</value> 
     </property> 
     <property name="username"> 
      <value>root</value> 
     </property> 
     <property name="password"> 
      <value>testn</value> 
     </property> 
    </bean> 


    <!-- Session Factory Declaration --> 
    <bean id="SessionFactory" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="DataSource" /> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 
     </property> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.airwatch.device.model.Employee</value> 
      </list> 
     </property> 
    </bean> 

    <!-- Enable the configuration of transactional behavior based on annotations --> 
    <tx:annotation-driven transaction-manager="txManager" /> 

    <!-- Transaction Manager is defined --> 
    <bean id="txManager" 
     class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
     lazy-init="true"> 
     <property name="sessionFactory" ref="SessionFactory" /> 
    </bean> 



    <!-- ........................DAO and Bussiness Configurations................. --> 
    <bean id="loginBussinessImpl" class="com.airwatch.device.bussinessImpl.LoginBussinessImpl"> 

    </bean> 
    <bean id="loginDaoImpl" class="com.airwatch.device.daoImpl.LoginDaoImpl"> 
    </bean> 
</beans> 

這是我的DAO類實現

public class LoginDaoImpl implements ILoginDao { 

     private Session mSession = null; 

     @Autowired 
     @Qualifier(value = "SessionFactory") 
     private SessionFactory mHibernateSessionFcatory; 

     /** 
     * @param sessionfactory 
     *   the sessionfactory to set 
     */ 
     public void setSessionfactory(SessionFactory sessionfactory) { 
      this.mHibernateSessionFcatory = sessionfactory; 
     } 

     @Override 
     public void empLogin_Dao(Employee employee) { 

      System.out.println("m in dao"); 

      mSession = mHibernateSessionFcatory.getCurrentSession(); 

      System.out.println(employee.getEmpID()); 

      Query query = mSession 
        .createQuery("from Employee where userName = :username "); 
      query.setParameter("username", employee.getUserName()); 
      List list = query.list(); 
      // mSession.getTransaction().commit(); 
      mHibernateSessionFcatory.close(); 
      mSession.close(); 

     } 

    } 
    ` 
+0

如果有任何人遇到此問題,請提前告知我,謝謝 – Subham 2012-08-10 11:55:30

回答

10

關閉整個會話工廠mHibernateSessionFactory.close()在你的DAO代碼中是一個明顯的不行。

此外,你不能訪問mSession關閉工廠後,它是在java文檔中說明。

void org.hibernate.SessionFactory.close() throws HibernateException

銷燬該SessionFactory並釋放所有資源(高速緩存, 連接池等)。

由於對這些會話的影響是不確定的,因此在調用此方法之前確保沒有公開會話是應用程序的責任。

如果您使用的是getCurrentSession()方法,典型的模式是委託會話打開和關閉,以春季和使用@Transactional註釋

 @Override 
     @Transactional 
     public void empLogin_Dao(Employee employee) { 

      System.out.println("m in dao"); 

      //Please note that declaring mSession as a class member is another no-no 
      //because DAO are typically singletons, so there's only ONE dao and ONE mSession variable 
      //that will be shared by all users - it's possible your class mSession field will be accessed 
      //simultaneously, which will lead to an exception 
      Session mSession = mHibernateSessionFactory.getCurrentSession(); 

      System.out.println(employee.getEmpID()); 

      Query query = mSession 
        .createQuery("from Employee where userName = :username "); 
      query.setParameter("username", employee.getUserName()); 
      List list = query.list(); 
     } 

您可以閱讀有關回滾政策here

+0

嗨,感謝它爲我工作。 – Subham 2012-08-13 04:29:07

+0

@ user1414185然後請接受是答案))) – 2012-08-13 09:14:41

+0

我確認,也解決了我的問題。打開封閉會話工廠(調用openSession)將會提供請求的未知服務[org.hibernate.stat.spi.StatisticsImplementor]。 – bmoc 2013-11-19 19:25:09

相關問題