Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when to use hibernate.connection.provider_class

Tags:

java

hibernate

When should I use hibernate.connection.provider_class? I am a little confused between it and 'hibernate.connection.diver_class'.

provider_class might be useful for connection pool

is there any other purpose where we can use provider_class?

like image 979
Ravi Parekh Avatar asked Jun 16 '11 13:06

Ravi Parekh


People also ask

What is the use of connection pooling 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 c3p0 hibernate connection pooling?

C3p0 is an open-source JDBC connection pooling library, with support for caching and reuse of PreparedStatements. Hibernate provides support for Java applications to use c3p0 for connection pooling with additional configuration settings.

What is hibernate connection pool size?

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.

What is hibernate c3p0 Max_size?

Likewise, the hibernate.properties file can contain the same settings: hibernate.c3p0.min_size=5 hibernate.c3p0.max_size=20 hibernate.c3p0.acquire_increment=5 hibernate.c3p0.timeout=1800. The min_size property specifies the minimum number of connections it should maintain at any given time.


3 Answers

Another use for connection provider is to uphold sessions over time, this is especially true with the combination of mysql + hibernate. If you don't have a properly configured connection provider that handles timeouts from mysql, you're likely to loose your connection to the database sooner or later if you have periods of inactivity.

like image 151
Martin Peters Avatar answered Oct 25 '22 14:10

Martin Peters


The driver class is what it sais it is, what driver do you use to connect to your db. The connection provider class is class that can manage your connections for you and provide it to the session.

Have a look at: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

The connection provider class is usually used if you want to use connection pooling. eg: hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider.

like image 38
joostschouten Avatar answered Oct 25 '22 13:10

joostschouten


ConnectionProvider is what you use to customize your strategy for obtaining connections. As well as connection pooling, it can be used to implement multi-tenancy databases.

A brief run-thru:

http://literatejava.com/hibernate/multi-tenancy-architecture-with-hibernate/

like image 22
Thomas W Avatar answered Oct 25 '22 13:10

Thomas W