Rule Definition
It is very important to define a connection pool to increase database access performances.
Hibernate's own connection pooling algorithm is quite rudimentary. It is intended to help you get started and is not intended for use in a production system or even for performance testing. Use a third party pool for best performance and stability.
Remediation
Use a third party connection pool like:
* c3p0 - http://sourceforge.net/projects/c3p0 - Distributed with Hibernate
* Apache DBCP - http://jakarta.apache.org/commons/dbcp/ - Apache Pool
* Proxool - http://proxool.sourceforge.net/ - JDBC Pooling Wrapper
* a connection pool from an external vendor
Violation Code Sample
---> hibernate.cfg.xml
...
<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/SessionFactory">
...
<property name="connection.pool_size">10</property> // VIOLATION
...
---> or in hibernate.properties
hibernate.connection.pool_size = 10 // VIOLATION
Fixed Code Sample
---> hibernate.cfg.xml
...
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory
name="java:comp/env/hibernate/SessionFactory">
<!-- properties -->
<property name="connection.datasource">my/first/datasource</property> // FIXED
...
</session-factory>
</hibernate-configuration>
---> or in hibernate.properties
...
hibernate.connection.datasource = my/first/datasource
...
Reference
http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html
http://www.informit.com/articles/article.asp?p=353736&seqNum=4&rl=1
Hibernate in Action (ISBN 1932394-15-X) p 45
Related Technologies
JEE
Technical Criterion
CWE-1072 - Data Resource Access without Use of Connection Pooling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.