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.
- right join/right outer join
- left join/left outer join
- inner join
- full 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;
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.
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.
In full join
, both equal data
and unequal data
from both sides of the joints will be selected.
full join = left join + right join.