Hibernate - SPLessons

Hibernate Joins

Chapter 27

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Hibernate Joins

Hibernate Joins

shape Description

The functionality of Hibernate Joins is to read the data from multiple entities by using relationship and construct in a single select operation, then use the HQL Join statements. When constructing a joint statement, to the left side of the join, there should be relationship owner and right side of the join should be reference variable. HQL Joins are of 4 Types.

Inner join

Inner join reads only equal data from both sides of the join statement. It is the by default join of Hibernate. Following is an example to perform inner join where a customer name and associated Item names use one-to-many relationship and apply between the Customer class and Item class.

select c.customerName, i.itemName from Customer c join c.items;


Left join

In left join, even if there is equal data of the association and more data will be selected from left side of the join statement. Following is an query where a customer Name is selected, even though there are no items for that customer.

select c.customerName,i.itemName from Customer c left join c.items.

Right join

In right join, even if there is equal data of the association and more data will be selected from right side of the join statement .

select c.customerName,i.itemName from Customer c right join c.items.

Full join

In full join, both equal data and unequal data from both sides of the joints will be selected.

full join = left join + right join.


shape Key Points

  • Hibernate Joins – HQL, Native SQL are used to perform join statements.
  • Hibernate Joins – Full join is a combination of right and left joints.
  • Hibernate Joins – Hibernate by default join is Inner join.