Lesson - 27 : Hibernate - Built-in connection pooling in Hibernate

Опубликовано: 30 Сентябрь 2024
на канале: Sada Learning Hub
1,656
23

Hibernate – Built-in Connection Pooling in Hibernate:
1. If a java program wants to obtain a connection with a database then java API as provided or JDBC API as provided two ways.
A) java.sql.DriverManager class
B) javax.sql.DataSource interface
2. If a java program want to get direct connection with the database then we use DriverManager class.
3. The connection returned by DriverManager class is a nonreusable connection. The non reusable connections will increase the burden on a database.
4. To overcome the above problem we got connection pooling technique in java.
5. In connection pooling a group of reusable connections(pooled connections) are stored in a pool and the connections are provided to the clients whenever required.
6. To obtain a connection from a connection pool we use DataSource interface in a java program

In hibernate connection pooling mechanism is divided into three types
1. Built-in connection pooling / jdbc connection pooling
2. Standalone connection pooing/Third party connection pooling
3. Server side connection pooling

Built-in connection pooling / jdbc connection pooling :
1. Hibernate by default comes with automatic connection pool. This is also called jdbc connection pool.
2. As a programmer we are allowed to set the maximum pool size for hibernate built- in connection pool
3. If you want to set maximum pool size then we need to configure connection pool size property in hibernate.cfg.xml file
4. <property name=“hibernate.connection.pool_size”>10</property>
5. The built- in connection pool of hibernate is only for testing purpose, but it should not be used in real time application (production.system)

Configurations:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="hibernate.connection.pool_size">50</property>
<mapping resource="Payment.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Hibernate Examples Project Github Link : https://github.com/SadaLearningHub1/H...