Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0
Mapping documents:Parent Table
<hibernate-mapping>
<class name="com.coassectt.dak.business.vo.CreateDakVO" table="dakdetails">
<id name="dakid" column="DAK_ID" type="integer" >
<generator class="native" />
</id>
<property name="subject" type="string">
<column name="DAK_SUBJECT" length="100"/>
</property>
<property name="dateDueBy" type="date">
<column name="DAK__DATE_DUEBY" length="20"/>
</property>
<set name="dakEdit" inverse="true" cascade="all" >
<key>
<column name="DAK_ID" not-null="true" />
</key>
<one-to-many class="com.coassectt.dak.business.vo.EditDakVO" />
</set>
</class>
</hibernate-mapping>
Child Table:
<hibernate-mapping>
<class name="com.coassectt.dak.business.vo.EditDakVO" table="EDITDAK">
<id name="dakEditId" column="DAK_EDIT_ID" type="integer" >
<generator class="native" />
</id>
<property name="department" type="string">
<column name="DE_FORWARDED_TO" length="40"/>
</property>
<property name="fwdDate" type="date">
<column name="DE_FORWARDED_DATE" length="20"/>
</property>
<property name="remarks" type="string">
<column name="DE_COAS_REMARKS" length="255"/>
</property>
<property name="dateDueBy" type="date">
<column name="DE_DATE_DUEBY" length="20"/>
</property>
<many-to-one name="createDak" class="com.coassectt.dak.business.vo.CreateDakVO" >
<column name="DAK_ID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
List dayendReptList=null;
Date today=new Date();
today.setDate(today.getDate()+5);
StringBuffer query = new StringBuffer();
query.append("select editvo.department,editvo.remarks,createVO.subject from com.coassectt.dak.business.vo.CreateDakVO createVO, com.coassectt.dak.business.vo.EditDakVO editvo where createVO.dakid = editvo.createDak.dakid").append(" and ").append("editvo.dateDueBy = '").append(DateUtil.convertDate(DateUtil.formatDate(today))).append("'");
dayendReptList = session.createQuery(query.toString()).list();
Iterator itr = dayendReptList.iterator();
while(itr.hasNext()){
// System.out.println("Class name"+itr.next().getClass().getName());
EditDakVO editDakVO=(EditDakVO)itr.next();//Here it is giving ClasscastException because hql is using two VOs.
Name and version of the database you are using:My SQL
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: