A major justification for using object/relational persistence layer against direct JDBC is its potential for caching. Although, we will repeat it again, nothing beats a good database design and good fetching strategies. There is no doubt that for some kinds of applications, caching can have a serious impact on performance.
We will introduce the Hibernate caching system and show how to enable and use the first and second level Hibernate cache. This information and these rules can be applied to caching in general and are valid for more than just Hibernate applications.
A cache is a representation of the current database state either in memory or on the disk of the application server machine. Hibernate uses different types of caches, which are used for different purposes. Let us first have a look at these cache types: