• Register
0 votes
1.1k views

Problem :

I am using the Hibernate for a first time for my project and I am very new to Hibernate. I think I have followed all the instructions written in some tutorials but still I keep getting the below Exception that is in my title:

Exception in thread "main" org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!

What I want to do is simply storing the object into the MySql Database that I have already created.

When I run it I always get above exception and I have no idea why. Maybe I should just change a connection.pool_size property, but if I do so it guesses that I only will get more errors. Can anyone help me?

7 5 2
3,870 points

1 Answer

0 votes

Solution :

 

Please do below changes in your HibernateUtil:

public static Session getHibernateSession() {

    final SessionFactory sf = new Configuration()
        .configure("yourConfig.cfg.xml").buildSessionFactory();

    // factory = new Configuration().configure().buildSessionFactory();
    final Session session = sf.openSession();
    return session;
    }

And instead of using the SessionFactory use the Session:

final Session session = HibernateUtil.getHibernateSession();

And after that use the below code:

Transaction tx = session.beginTransaction();
 // all your methods
 tx.commit();
 session.close();

Hope this helps you in resolving your issue.

And you can actually remove that connection pool property from your hbm if you do not need it.

9 7 4
38,600 points

Related questions

1 vote
1 answer 134 views
134 views
Problem : I am very new to SQL Queries. Recently I have joined new team and I am given below task Find the country that has all the vowels and no spaces in its name? I have written below query SELECT country FROM world WHERE country LIKE '%u'       and country LIKE ... of time in writing the correct query but still unable to do it. So I am looking for sql experts help in fixing my above query.
asked Apr 17 stewart 4k points
0 votes
1 answer 4 views
0 votes
1 answer 60 views
0 votes
1 answer 162 views
162 views
Problem : I am getting bellow error java.sql.sqlexception lock wait timeout exceeded try restarting transaction I am using Java Struts 2.1 Hibernate configuration. DB Used is MYSQL. Anyone know how to solve it..??
asked Oct 23, 2019 peterlaw 6.9k points