Join in Hibernate by R4R Team

Hibernate follows the some basic element for the mapping. It is possible to map properties of one class to serval tables that have a one to one relationship.It can be done Using the <join> element.









<key ... /> <property ... /> ... </join>

To understand the above code we given the description of each part of the example below:




It sows the name of the table.


It overrides the schema name secified by the root <hibernate-mapping> element.


It override the catalog name specified by the root <hibernate-maping> element.


It found defaults join.

If set of join, default hibernate will use an inner join to retrieve a <join> defined by a class or its superclasses. It will use an outer join for a <join> defined by a subclass. If set to select then hibernae will use a sequential select for a <join> defined on a subclass. This will be issued only if a row represent an instance of the subclass. Inner joins will still be used to retrieve a <join> defined by the classes and its superclass.


It found defaults to false.

If enabled, Hibernate will not insert or update the properties defined by this join.


It defaults set to false.

If enabled, hibernate will insert a row only if the properties defined by this join are non-null. It will always use an outer join to retrieve the proerties.

For this to understand we take a example:

Address information for a person can be mapped to a separate table while preserving value type semantics for all properties:

<class name="Person" table="PERSON"> 

<id name="id" column="PERSON_ID">...</id> 

<join table="ADDRESS"> <key column="ADDRESS_ID"/> 

<property name="address"/> <property name="zip"/> 

<property name="country"/> </join> ...

In this example this feature is often only useful for legacy data models. We recommend fewer tables than classes and a fine-grained domain model. However, it is useful for switching between inheritance mapping strategies in a single hierarchy, as explained later.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!