Hibernate Inheritance Strategies

Hibernate supports following strategies to support Inheritance mappings in database: Single Table or Table per class-hierarchy (InheritanceType.SINGLE_TABLE) Joined or Table per subclass (InheritanceType.JOINED) Table per class (InheritanceType.TABLE_PER_CLASS)   Single Table strategy(aka Table per class-hierarchy) In this strategy, a single table is created for each class hierarchy. So, if we have a base class “Book” and […]

Hibernate Query Cache

In Hibernate, we can cache frequently used query results using Query cache. To enable Query cache, enable the “use_query_cache” property in hibernate.cfg.xml file : <property name="hibernate.cache.use_query_cache">true</property> To use Query cache, we also need to set the cacheable property on the Query to true by invoking the Query.setCacheable() method. Hibernate Query Cache Example In the following […]

Hibernate Caching : Second Level Cache

Second Level Cache or L2 Cache The Second Level Cache in Hibernate is optional and is external to Hibernate. This cache is globally available via the SessionFactory class to the entire application. Hibernate comes with built-in support for caching libraries Ehcache and Infispan. However, any Cache provider can implement the org.hibernate.cache.spi.CacheProvider interface provided and provide […]

Hibernate Caching : First Level Cache

Hibernate provides multilevel caching framework : First Level Cache (Also called L1 cache or Session cache) Second Level Cache (L2 Cache) Query Cache   First Level Cache / L1 Cache / Session Cache The First level cache(L1 cache) is the Session cache through which all the db requests must pass. The L1 cache ensures that […]

Selecting data from database using HQL

HQL Hibernate has its own query language called HQL(Hibernate Query Language). HQL is object oriented. In HQL, we use the class name in place of table name and property name in place of column name. HQL queries are internally converted to SQL by Hibernate.   FROM clause Using just the From clause fetches all the […]