Skip to content
Advertisement

Does hibernate SessionFactory.openSession() wait for a database connection to be available from pool

Does hibernate SessionFactory.openSession() wait for a database connection to be available from pool ?

I assumed it did, but I have customer with this exception

JavaScript

making me think it isn’t, or is it waiting for a certain time and then giving up, I am using Hibernate 4.3.11 with C3p0 and H2 1.5

My Hibernate config is

JavaScript

Advertisement

Answer

Hibernate SessionFactory openSession() method always opens a new session. you should close this session object once you are done with all the database operations. Session objects are not thread safe,you should open a new session for each request in multi-threaded environment

base on this refrence https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/SessionFactory.html#openSession()

Session openSession() throws HibernateException Open a Session. JDBC connection(s will be obtained from the configured ConnectionProvider as needed to perform requested work.

Returns: The created session. Throws: HibernateException – Indicates a peroblem opening the session; pretty rare here.

also you can check this links to resolve problem:

A ResourcePool could not acquire a resource from its primary factory or source

com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement