Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Joined SubClass List Retrieval
PostPosted: Wed Dec 28, 2016 5:29 am 
Newbie

Joined: Wed Dec 28, 2016 5:15 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.