Using Relation Table
Previous Home Next

In this approach the relation table is used to manage the relation between obect. Primary key of both objects are used as foreign key in relation table .


  • support one-to-many ,if any time one name has many address then it support it.


  • Performance is degraded.


In this approach three tables are used

  • Table for Batch(id,name)
  • Table for Trainer(id,name,fees)
  • Table for Relation(batchid,trainerid)


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<!-- Generated by MyEclipse Hibernate Tools. -->
<class name="r4r.Address">
<id name="id" type="int">
<generator class="increment"></generator>
<property name="city"></property>
<property name="street"></property>
<class name="r4r.Person" table="person3">
<id name="id" type="int">
<generator class="increment">
<property name="name"></property>
<join table="addresses">
<key column="personid">
<many-to-one name="address" class="r4r.Address" 
cascade="all" column="addressid" unique="true">
Previous Home Next