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...
|