Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7845093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:06:45+00:00 2026-06-02T17:06:45+00:00

I have a simple class which starts 3 threads and saves a new object

  • 0

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?

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());

    }
}

And this is the relevant part of the log file showing the exception:

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)

EDIT 1

<?xml version='1.0' encoding='utf-8'?>

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
    <property name="connection.username">vishnu</property>
    <property name="connection.password">con02305</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup 
    <property name="hbm2ddl.auto">update</property> -->

    <property name="default_schema">test</property>
    <property name="show_sql">true</property>

    <mapping resource="domain/Event.hbm.xml"/>

</session-factory>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:06:47+00:00Added an answer on June 2, 2026 at 5:06 pm

    Session object in Hibernate is not thread safe, you should not use the same session in different threads, unless you synchornize access to Session object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple program which starts n threads and create some load on
I have a simple class which does reverse geocoding, but it causes the app
I have a simple Java class in which I invoke a call to a
I have a simple model class (Part), which pulls from it's information from a
i have created a simple public ref class in the vc++ project, which is
I have a static class called Helpers which contains a good number of simple
So i have a class name repository which is just a simple array.Here is
I have a simple python script which calls 6 threads and for some reason
I'm following the example given in http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/ I have a thread which is checking
I have the following thread which simply prints a dot every 200ms: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.