-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL join of three tables
PostPosted: Mon Oct 30, 2006 2:37 am 
Newbie

Joined: Fri Oct 13, 2006 6:43 am
Posts: 5
Hi All,

Iam using hibernate along with spring framework to fetch a list using Hibernate HQL joins. And my code is...

List list1=new ArrayList();
List lst=getHibernateTemplate().getSessionFactory().openSession().createQuery("select c.codeId,c.codeName,cd.codevalueid,sd.displayname from Code as c join c.codeValueSet as cd join cd.surveySet as sd").list();

Iterator iter = lst.iterator();
while (iter.hasNext())
{

System.out.println(iter.toString());

Object[] obj = (Object[])iter.next();
System.out.println("long value is");

Code c = new Code();
c.setCodeId((Long)obj[0]);
c.setCodeName((String)obj[1]);
Set c1=new HashSet();
CodeValue cd=new CodeValue();
cd.setCodevalueid((Long)obj[2]);
c1.add(cd);
c.setCodeValueSet(c1);
list1.add(0,c);

CodeValue cd1=new CodeValue();
Set c2=new HashSet();
Survey s=new Survey();
s.setDisplayname((String)obj[3]);
System.out.println("long value is" +(String)obj[3]);
c2.add(s);
cd1.setSurveySet(c2);
list1.add(1,cd1);



}

return list1
}

I used c:forEach to display the results in jsp..

Code for that is...


<c:forEach items="${users}" var="cde" >

<c:out value="${cde.codeId}" />
<c:out value="${cde.codeName}" />


<c:forEach items="${cde.codeValueSet}" var="cv" varStatus="cvStatus">
<c:out
value="${cv.codevalueid}" />
<br/>


</c:forEach>

<c:forEach items="${cde.surveySet}" var="cv1" varStatus="cv1Status">
<c:out
value="${cv1.displayname}" />
<br/>

</c:forEach>



</c:forEach>

Here users list is list1...


But iam getting below error ...

javax.servlet.ServletException: Unable to find a value for "surveySet" in object
of class "sessionfactory.Code" using operator "."


I tried by removing the following from the code and jsp

CodeValue cd1=new CodeValue();
Set c2=new HashSet();
Survey s=new Survey();
s.setDisplayname((String)obj[3]);
System.out.println("long value is" +(String)obj[3]);
c2.add(s);
cd1.setSurveySet(c2);
list1.add(1,cd1);

and

<c:forEach items="${cde.surveySet}" var="cv1" varStatus="cv1Status">
<c:out
value="${cv1.displayname}" />
<br/>

</c:forEach >


And it worked properly by displaying results.

But i want to display "displayname" property which is in surveySet ..

How can i do this?

Help me...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.