Hi All,
I need some help to write my hbm file ,the scenario will be as below:
I have a super class 'A' and subclasses B , C and the Java classes will be as follows:
public abstract class Z{ private String classCode; //Setter and getter methods }
public class A extends Z{ private String city; private String state; private String name; //Setter and getter methods }
public class B extends A{ private String email; //Setter and getter methods }
public class C extends A{ private String temp; //Setter and getter methods }
Now i have a hibernate mapping file as follows:
<hibernate-mapping> <class name="A" table="a" abstract="true" proxy="A"> <id name="id" unsaved-value="0"> <generator class="native" /> </id> <discriminator column="class_code" type="string"/> <property name="classCode" column="class_code" type="string" insert="false" update="false" /> <property name="name" type="string" column="name" /> <property name="city" type="string" column="city" /> <property name="state" type="string" column="state" /> <subclass name="A" discriminator-value="a" proxy="A"> <property name="email" type="string" column="email" /> </subclass>
<subclass name="B" discriminator-value="b" proxy="B"> <property name="temp" type="string" column="temp" /> </subclass> </class> </hibernate-mapping>
Now i want to introduce one more class D which will be something like this :
public class D extends Z{ private String name; private String description; private long mappingId; } and has a table for this object with primary key 'id' ;
Now i want to have list of Ds for B , C;
so the classes will be modified something like below:
public class B extends A{ private String email; private List<D> = new ArrayList<D>(); //Setter and getter methods }
public class C extends A{ private String temp; private List<D> = new ArrayList<D>(); //Setter and getter methods }
Now i want have a database design as below:
I should have only one table for 'D' and one table for each Class which will have this D as a list.(for example the classes B and C).Now i have to map these tables as below:
I will have two columns class_code and mapping_id for table 'D' and want to access the rows from this table using the combination of these two fields as a composite key.
Note :-- I don't want to have any extra mapping tables for this mapping .But i want to retrieve the data from table 'D' by using the combination of class_code and mapping_id as a composite key.
Then how can i map this scenario in the given hbm file ? Please help me to solve this.
Thanks in advance Raj
|