title: UnknownServiceException: Unknown service requested (Hibernate/Spring)
body: <p>This problem bothers me now for days ..</p>
  
  <p>I'm trying to get the current session from my <code>sessionFactor</code> but receive an <code>org.hibernate.service.UnknownServiceException: Unknown service requested</code> exception.</p>
  
  <p>I have no idea what causes this or what this exception does mean in particular. The exception gets thrown as <code>getCurrentSession()</code>gets called.</p>
  
  <pre><code>@Component
  public class RestaurantOwnerRepository implements RestauranOwnerDAO {
  
      private SessionFactory sessionFactory;
  
      public RestaurantOwnerRepository(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      @Override
      @Transactional
      public List&lt;Restaurant&gt; getAvailableRestaurants(String sessionId) {
  
          Session session = sessionFactory.getCurrentSession();
          // ..
      }
  }
  </code></pre>
  
  <p>which I am calling in my servlet:</p>
  
  <pre><code>@Configurable
  public class RestaurantInformationServiceImpl  extends XsrfProtectedServiceServlet implements RestaurantInformationService {
      private static final long serialVersionUID = -4088840947018614411L;
  
      private final static Logger logger = Logger.getLogger(RestaurantInformationServiceImpl.class);
  
      @Autowired
      public RestauranOwnerDAO restaurantOwnerRepository;
  
      @Override
      public void init(ServletConfig config) throws ServletException {
          super.init(config);
  
          ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/appServlet/servlet-context.xml");
  
          this.restaurantOwnerRepository = (RestauranOwnerDAO)applicationContext.getBean("restaurantOwnerRepository");
  
          ((ConfigurableApplicationContext)applicationContext).close();
      }
  
      @Override
      public List&lt;RestaurantDTO&gt; getAvailableRestaurants() {
  
          List&lt;Restaurant&gt; availableRestaurants = restaurantOwnerRepository.getAvailableRestaurants(getSessionId());
          // ..
      }
  }
  </code></pre>
  
  <p>This is my <strong>servlet-context.xml</strong> file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
          infrastructure --&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
          in the /WEB-INF/views directory --&gt;
      &lt;bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;context:component-scan base-package="com.mahlzeit.web.server" /&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/mahlzeit_db" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation" value="classpath:hibernate-webserver.cfg.xml" /&gt;
      &lt;/bean&gt;
  
  
  &lt;!--    &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; --&gt;
      &lt;tx:annotation-driven/&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="restaurantOwnerRepository" class="com.mahlzeit.web.server.dao.RestaurantOwnerRepository"&gt;
          &lt;constructor-arg&gt;
              &lt;ref bean="sessionFactory" /&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>And this my <strong>hibernate-webserver.cfg.xml</strong> file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
  
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/mahlzeit_db&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;&lt;/property&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Batch size --&gt;
          &lt;!-- &lt;property name="hibernate.jdbc.batch_size"&gt;20&lt;/property&gt; --&gt;
  
          &lt;!-- Echo all executed SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;false&lt;/property&gt;
          &lt;property name="format_sql"&gt;false&lt;/property&gt;
  
          &lt;!-- Drop and re-create the database schema on startup --&gt;
          &lt;!-- &lt;property name="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/property&gt; --&gt;
          &lt;!-- Run Hibernate in update mode --&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
  
          &lt;!-- JDBC connection pool (use the built-in) --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;!-- Bind the getCurrentSession() method to the thread --&gt;
          &lt;!-- &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; --&gt;
  
          &lt;!-- Mappings ... --&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Error message/stack trace:</p>
  
  <pre><code>com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.mahlzeit.web.shared.service.restaurant.RestaurantInformationService.getAvailableRestaurants()' threw an unexpected exception: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
          at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:415)
          at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:605)
          at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)
          at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)
          at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
          at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
          at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
          at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
          at java.lang.Thread.run(Thread.java:745)
      Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
          at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:126)
          at org.hibernate.internal.AbstractSessionImpl.getJdbcConnectionAccess(AbstractSessionImpl.java:261)
          at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.&lt;init&gt;(JdbcCoordinatorImpl.java:97)
          at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.&lt;init&gt;(TransactionCoordinatorImpl.java:87)
          at org.hibernate.internal.SessionImpl.&lt;init&gt;(SessionImpl.java:254)
          at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1609)
          at org.hibernate.internal.SessionFactoryImpl.openSession(SessionFactoryImpl.java:973)
          at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:122)
          at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:988)
          at com.mahlzeit.web.server.dao.RestaurantOwnerRepository.getAvailableRestaurants(RestaurantOwnerRepository.java:62)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
          at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:266)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
          at com.sun.proxy.$Proxy50.getAvailableRestaurants(Unknown Source)
          at com.mahlzeit.web.server.service.restaurant.RestaurantInformationServiceImpl.getAvailableRestaurants(RestaurantInformationServiceImpl.java:50)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:587)
          ... 25 more
  </code></pre>
  
  <p>I just don't have any idea how to solve that problem. 
  Any help on this would be appreciated!</p>