Working with a first-level cache

Once we execute a particular query using hibernate, it always hits the database. As this process may be very expensive, hibernate provides the facility to cache objects within a certain boundary.

The basic actions performed in each database transaction are as follows:

  1. The request reaches the database server via the network.
  2. The database server processes the query in the query plan.
  3. Now the database server executes the processed query.
  4. Again, the database server returns the result to the querying application through the network.
  5. At last, the application processes the results.

This process is repeated every time we request a database operation, even if it is for a simple or small query. It is always a costly transaction ...

Get Java Hibernate Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.