title: Hibernate UnknownServiceException :Unknown service requested as transaction completed
body: <p>I have a simple class which starts 3 threads and saves a new object in each thread. But I am getting exception which i cannot understand. Can anyone help me understand why the exception?</p>
  
  <pre><code>package test;
  
  import java.util.Date;
  
  import org.hibernate.Session;
  
  import domain.Event;
  
  import util.HibernateUtil;
  
  public class EventBeanTest {
  
      public static void main(String [] args) {
  
          Event e1 = new Event();
          e1.setTitle("111");
          e1.setDate(new Date());
  
          Event e2 = new Event();
          e2.setTitle("222");
          e2.setDate(new Date());
  
          Event e3 = new Event();
          e3.setTitle("333");
          e3.setDate(new Date());
  
  
          Thread t1 = new Thread(new EventRunnable(e1));
          Thread t2 = new Thread(new EventRunnable(e2));
          Thread t3 = new Thread(new EventRunnable(e3));
  
          t1.setName("event - 111");
          t2.setName("event - 222");
          t3.setName("event - 333");
  
          t1.start();
          t2.start();
          t3.start();
  
      }
  
  }
  
  class EventRunnable implements Runnable {
      private Event event;
  
      public EventRunnable(Event event) {
          this.event = event;
      }
  
      public void run() {
  
          System.out.println("Starting thread : " + Thread.currentThread().getName());
  
          Session session = HibernateUtil.getSessionFactory().getCurrentSession();
  
          session.beginTransaction();
  
          session.saveOrUpdate(event);
          session.getTransaction().commit();
  
          HibernateUtil.getSessionFactory().close();
  
          System.out.println("Finishing thread : " + Thread.currentThread().getName());
  
      }
  }
  </code></pre>
  
  <p>And this is the relevant part of the log file showing the exception:</p>
  
  <pre><code>Hibernate: select max(EVENT_ID) from test.EVENTS
  Hibernate: insert into test.EVENTS (EVENT_DATE, TITLE, EVENT_ID) values (?, ?, ?)
  Hibernate: insert into test.EVENTS (EVENT_DATE, TITLE, EVENT_ID) values (?, ?, ?)
  Hibernate: insert into test.EVENTS (EVENT_DATE, TITLE, EVENT_ID) values (?, ?, ?)
  Apr 22, 2012 2:46:55 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
  INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/test]
  Finishing thread : event - 333
  Apr 22, 2012 2:46:55 PM org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction afterAfterCompletion
  INFO: HHH000425: Could not close session; swallowing exception[org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]] as transaction completed
  Exception in thread "event - 222" 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:1708)
      at org.hibernate.internal.SessionFactoryImpl.getStatistics(SessionFactoryImpl.java:1704)
      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.commit(AbstractTransactionImpl.java:184)
      at test.EventRunnable.run(EventBeanTest.java:60)
      at java.lang.Thread.run(Thread.java:722)
  Apr 22, 2012 2:46:55 PM org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction afterAfterCompletion
  INFO: HHH000425: Could not close session; swallowing exception[org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]] as transaction completed
  Exception in thread "event - 111" 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:1708)
      at org.hibernate.internal.SessionFactoryImpl.getStatistics(SessionFactoryImpl.java:1704)
      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.commit(AbstractTransactionImpl.java:184)
      at test.EventRunnable.run(EventBeanTest.java:60)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <pre><code>&lt;session-factory&gt;
  
      &lt;!-- Database connection settings --&gt;
      &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/test&lt;/property&gt;
      &lt;property name="connection.username"&gt;vishnu&lt;/property&gt;
      &lt;property name="connection.password"&gt;con02305&lt;/property&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
      &lt;!-- SQL dialect --&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
      &lt;!-- Enable Hibernate's automatic session context management --&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache  --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop and re-create the database schema on startup 
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt; --&gt;
  
      &lt;property name="default_schema"&gt;test&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;mapping resource="domain/Event.hbm.xml"/&gt;
  
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>