Inheritance Strategy in Hibernate

Hibernate comes with a provision to create tables and populate them as per the Java classes involved in inheritance. Hibernate offers basically three different approaches to map hierarchical classes – classes involved in inheritance with database tables. There are three types of inheritance strategy – Table per class hierarchy, Table per sub-class and Table per concrete class.

Hibernate Inheritance strategy: Table Per Class Hierarchy

Introduction I am going to give explanation and example on hibernate table per class hierarchy. Let’s consider you have a base class named Person and two derived classes – Student and Teacher. If you save the derived class object like Student or Teacher then automatically Person class object will also be saved into the database, and in the database all…

Hibernate Inheritance strategy: Table Per SubClass Hierarchy

Introduction In Table Per SubClass Hierarchy there will be the number of classes equals to the number of tables in the database. If you save the Student class object, hibernate will first save the data related to super class object into the super class related table in the database and then Student object data in Student related table in the…

Hibernate Inheritance strategy: Table Per Concrete Class Hierarchy

In Table Per Concrete Class Hierarchy will have the number of tables in the database equals to the number of derived classes. Once you save the derived class object, then derived class data and base class data will be saved in the derived class related table in the database. You need tables only for the derived classes. For this in…

Different types of cache strategies in Hibernate

Introduction In this tutorial I will tell you different types of caches in Hibernate framework. Hibernate is an ORM (Object Relational Mapping) framework. Hibernate uses two different caches for objects: first-level cache and second-level cache. If you have queries that run over and over, with the same parameters, query caching provides performance gains. Caching introduces overhead in the area of…

Criteria API example in Hibernate

Introduction Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like “search” screens where there is a variable number of conditions to be placed upon the result set. We will configure hibernate using Java based configuration, for example, we will build SessionFactory with required configurations using Java code. So…

Spring AOP (Aspect Oriented Programming) Example

With this tutorial we will see how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide declarative enterprise services. It is also used to allow users to implement custom aspects, complementing their use of OOP with AOP. We will demonstrate how to create and apply some central AOP concepts. In short we…

Spring MVC and Spring JDBC Example

Introduction This tutorial shows an example on how MVC (Model, View, Controller) works in Spring framework. In this tutorial you will also find how JDBC (Java Database Connectivity API) works with Spring MVC. We will also see how annotation like @Autowired works in Spring. You will also see how datasource is configured in Spring. This example shows how to read…

Transaction Management in Spring

Transaction in Spring Here I will tell you about the transaction management in Spring framework. I will later also show you with examples how programmatic and declarative transaction management happen in Spring framework. A transaction is a logical unit of work that contains one or more statements with the following features: Transaction management is an important part of enterprise applications…

Declarative Transaction Management Example in Spring

Declarative Transaction This tutorial shows an example on declarative transaction management in Spring framework. You may also want to know about Spring Transaction or Declarative Transaction management in Spring. Here I will create annotation based Spring stand alone and Spring Boot applications to create Declarative Transaction Management example in Spring framework. Here I will use H2 in-memory database to create…