Code:
ClassA Extends ClassB {
List<ClassC> classCList;
// bunch of getters and setters
}
Hibernate mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 16, 2016 4:44:43 PM by Hibernate Tools 5.1.0.Beta1 -->
<hibernate-mapping package="com.dto">
<class name="ClassB " table="ClassB ">
<id name="classBId" type="java.lang.Integer">
<column name="classBId" />
<generator class="identity" />
</id>
<key column="ClassBId" />
// // bunch of property tag to specify the attributes of class
<property name="tag" />
<joined-subclass name="ClassA" table="ClassA " extends="ClassB">
<key column="ClassBId" />
// bunch of property tag to specify the attributes of class
<list name="classCList" table="ClassC" inverse="true" lazy="true"
fetch="select" cascade="all">
<key>
<column name="classAId" not-null="true" />
</key>
<list-index column="idx" />
<one-to-many class="ClassC" />
</list>
</joined-subclass>
</class>
<class name="ClassC" table="ClassC" optimistic-lock="version">
<id name="classCId" type="java.lang.Integer">
<column name="classCId" />
<generator class="identity" />
</id>
// bunch of property tag to specify the attributes of class
<property name="name" type="string">
<column name="name" />
</property>
</class>
</hibernate-mapping>
Method to retrieve the List of Class C is as follows:
Code:
Criteria crit = session.createCriteria(ClassA.class);
crit.add(Restrictions.eq("revison", revison));
crit.setMaxResults(25);
classAlist = (List<ClassA> )crit.list();
for(ClassA classA: classAlist ) {
List<ClassC> classCList = classA.getclassCList ();
//here the list named classCList is empty.
Provide suggestions to retrieve the classCList .
But if I change the key column of the Joined-subclass to the following:
Code:
<joined-subclass name="ClassA" table="ClassA " extends="ClassB">
<key column="ClassAId" />
// bunch of property tag to specify the attributes of class
<list name="classCList" table="ClassC" inverse="true" lazy="true"
fetch="select" cascade="all">
<key>
<column name="classAId" not-null="true" />
</key>
<list-index column="idx" />
<one-to-many class="ClassC" />
</list>
</joined-subclass>
Then the ClassC list has last element added.
Need to retrieve all elements of the list in ClassC. Please Suggest