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 8020257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:38:17+00:00 2026-06-04T21:38:17+00:00

I am using Hibernate 3 and mysql sever 5.5 for myweb application with spring

  • 0

I am using Hibernate 3 and mysql sever 5.5 for myweb application with spring 3.0

I am getting exception as Too many connections……

My java file where I create session is as follows:

public class DBConnection {

    static{

    }

    public Session getSession(){

         Session session = null;
         SessionFactory sessionFactory= null;
         sessionFactory = new Configuration().configure().buildSessionFactory();
        session = sessionFactory.openSession();
        return session;

    }

}

and I call this method where I need session

as

Session session=new DBConnection().getSession();

and after

transaction.commit();

I close session by using

session.close();

please help me in solving problem…….

my hibernate.cfg.xml is :

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbname</property>
<property name="hibernate.connection.username">root</property>

  <property name="hibernate.connection.password">lax</property>
  <property name="hibernate.connection.pool_size">100</property>
  <property name="show_sql">true</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <property name=""></property>

  <property name="hibernate.connection.release_mode">on_close</property>

</session-factory>
</hibernate-configuration>
  • 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-04T21:38:19+00:00Added an answer on June 4, 2026 at 9:38 pm

    This is because you are using a connection pool which got created as soon as you build SessionFactory, but the connections are acquired only when you open a Session. Now, you are closing the session, due to which connections are released, but are not closed and are held up by the pool. Now, you are again creating a SessionFactory, hence creating a new pool, then getting a session, hence creating a new connection and so on.. which will eventually reach the maximum number of connections allowed.

    What you have to do is using one Connection Pool (using one SessionFactory) and getting and releasing the connections from the same pool.

    public class DBConnection {
    
          private static SessionFactory factory;
          static {
                factory = new Configuration().configure().buildSessionFactory();
          }
    
          public Session getSession() {
                return factory.openSession();
          }
    
          public void doWork() {
               Session session = getSession();
               // do work.
               session.close();
          }
    
         // Call this during shutdown
         public static void close() {
              factory.close();
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load a CSV file in to mySQL database using Java+Hibernate+Spring.
I'm using: Hibernate MySQL jBoss I have to create an application that allows user
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I'm working on a web application using spring, Glassfish, hibernate and MySQL. I have
I have a problem with Hibernate (3.6.0.-Final) in my Java EE application using MySQL
I am using Hibernate to access MySQL database for my java application. I configured
I am using Hibernate and mySQL. I develop the java application mostly on windows.
I'm using Hibernate 4.0.1.Final and MySQL 5.1. My domain object contains a java.util.Calendar object
I'm using Hibernate with JPA and MySQL. I got accessing denied. java.sql.SQLException: Access denied
i am using spring 3 , JSF 2 , MYSQL , Hibernate , and

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.