• Register
0 votes
1.5k 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

Please log in or register to answer this question.

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 231 views
231 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, 2020 stewart 4k points
0 votes
1 answer 10 views
0 votes
1 answer 71 views
0 votes
1 answer 213 views
213 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
0 votes
2 answers 560 views
560 views
Problem : I am new to the Spring and JPA, wasted 10 days and no result with the searching on internet. I want to save the object to SQL SERVER, my connection is correct but when I write .flush() I get below exception “nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress”
asked Jan 21, 2020 jwilliam 3.9k points
0 votes
1 answer 295 views
295 views
Problem : I am new to Spring and JPA I want to save object to SQL SERVER, connection is correct but when I write .flush() I get the exception as below javax.persistence.TransactionRequiredException: no transaction is in progress
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
2 answers 100 views
100 views
Problem : Here I want to copy all the objects in the List with object1 to a list with object2: Following is my code snip: List<EmployeeAmManegmentModel> AM = employee.amEmployeeDeatails(); List<EmployeeRmManegmentModel> RM = employee.rmEmployeeDeatails(); List< ... Long status; private String employeeType; How can I copy the result from one list of different object type to another?
asked Dec 3, 2019 alecxe 7.5k points
0 votes
1 answer 28 views
28 views
The connection's current state is Connecting. When attempting to connect to the MSSQL database via ASP.NET online.
asked Aug 29, 2020 Sofi55 1.1k points