Performance-tuning the persistent layer means starting at the bottom with a good database design with correct indexes, well tuned queries, and a thought-through choice of isolation level. If JDBC is used directly, make sure that connection pooling is used, and investigate what the application may gain by using fetch size, batch updates, and prepared statements.
With Hibernate and the JPA specifications, the gap between the relational database layer and the Java objects is bridged. In the Java layer, tuning can be performed using the following techniques and strategies:
Retrieving data with Hibernate and JPA requires applying the correct fetch strategy. Lazily loaded data avoids the cost of early loading relationships. This, however, carries the problem of additional queries executed to fetch the parent-child relationship, also known as n+1 problem.
Pagination can be used by means of the
setFirstResult()
orsetMaxResults()
method of theQuery
class. This allows loading a smaller page...