Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: What is the connection pool and why is the default one unsuitable for production?

I'm very unfamiliar with Hibernate and have just started working on a web app that uses it with a MySQL database. I notice that the community documentation tutorial states:

The built-in Hibernate connection pool is in no way intended for production use. It lacks several features found on any decent connection pool.

Can someone elaborate on this? What exactly is it missing and what are problems people have with the 'default' one? On googling I found a website here but it doesn't really explain the problems, just what you should be using instead.

like image 790
Kryptic Avatar asked Feb 02 '11 22:02

Kryptic


People also ask

What is connection pool in hibernate?

A connection pool is used to minimize the number of connections opened between application and database. It serves as a librarian, checking out connections to application code as needed.

What is connection pooling and why it is used?

Connection pooling means that connections are reused rather than created each time a connection is requested. To facilitate connection reuse, a memory cache of database connections, called a connection pool, is maintained by a connection pooling module as a layer on top of any standard JDBC driver product.

Which is best connection pool for hibernate?

C3P0 is an open source JDBC connection pool distributed along with Hibernate in the lib directory. Hibernate will use its org. hibernate.

What is the default connection pool size in hibernate?

The Hibernate Connection Pool Size property establishes the number of connections that are permitted between the Model repository and the Model Repository Service database. The default value is 10. In deployments with many concurrent connections, you can increase the property to increase performance.


1 Answers

What is the connection pool and why is the default one unsuitable for production? Can someone elaborate on this?

Connection pooling is a technique to open/prepare/close connections. A connection pooling mechanism is a piece of software (component), to which you delegate the function of managing connections. Your application would just ask for a connection, use it, and deliver it back to the pool. The component is responsible for opening N connections and leave them ready for when your application asks. If a connection is stale, the pooling mechanism would then close it and reopen a new one. This represents a better usage of connections, as you don't need to wait for the connection to be established during the actual execution of your code and you don't have to worry about stale connections.

Hibernate doesn't really ship any real connection pooling mechanism. It provides an internal connection manager, which is very rudimentary. The reason is simple: almost (if not all) Application Servers (like JBoss AS) and Servlet Containers (like Tomcat) provides a connection pooling mechanism by default. Thus, your application don't have to worry about the details about it. It just asks the AS for a connection.

In my opinion, there are only two cases where you need to worry about connection pooling:

  1. You are dealing with a standalone application (which doesn't run inside a container)
  2. You are really expert in connection pooling and none of the existing suits your needs.

But in my experience, most people that uses an "external" connection pooling do so for lack of knowledge about connection pooling and lack of knowledge about their container.

like image 70
jpkrohling Avatar answered Oct 05 '22 19:10

jpkrohling