Joined-subclass in Hibernate by R4R Team

In Hibernate each subclass can also be mapped to its own table. We called to this is table-per-subclass mapping strategy. An inherited state is retrieved by joining with the table of the superclass. For doing this need to use this <joined-subclass> element. 

For example:






dynamic-update="true|false" dynamic-insert="true|false" schema="schema" catalog="catalog" extends="SuperclassName" persister="ClassName" subselect="SQL expression" entity-name="EntityName" node="element-name"> <key .... > <property .... /> ..... </joined-subclass>

Here is the description of the all above:




fully qualified class name of the subclass


the name of the subclass table

proxy (optional)

specifies a class or interface used for lazy initializing proxies

lazy (optional)

defaults to true.

setting lazy="false" disables the use of lazy fetching

We have to remember a discriminator column is not required for this mapping strategy. Each subclass must, declare a table column holding the object identifier using the <key> element. 

How to write the mapping file it is given below:

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" ""> <hibernate-mapping package="eg"> 
<class name="Cater" table="CATS"> 
<id name="id" column="uid" type="long"> 
<generator class="hilo"/> 
<property name="birthdate" type="date"/>
 <property name="color" not-null="true"/> 
<property name="sex" not-null="true"/> 
<property name="weight"/> 
<many-to-one name="mate"/> 
<set name="kittens"> 
<key column="MOTHER"/> 
<one-to-many class="Cater_1"/> 
</set> <joined-subclass name="DomesticCat" table="DOMESTIC_CATS"> 
<key column="CAT"/> 
<property name="name" type="string"/> 
</class> <class name="eg.Dog"> 
<!-- mapping for Dog could go here --> </class> </hibernate-mapping>
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!