jsp - Hibernate criteria query to display children -


i trying develop simple web application using hibernate data portion. basically, attempting table row each category. in 1 cell each row, want display kpis category. that, attempting use criteria object. immediate problem nothing can results in second query firing.

here relevant bits code. i've tried sorts of things, i've got.

category.java

    @entity @table(name="category") public class category {     @id     @column(name="category_id")     @generatedvalue(strategy=generationtype.identity)     private int id;      @column(name="category_name")     private string categoryname;      @transient     private kpi[] kpis; ...     public kpi[] getkpis() {         return this.kpis;     } } 

categorydao

public interface categorydao {      public list<category> listcategories();     public category getcategorybyid(int id);     public list<kpi> getkpisforcategory(int cat); } 

categorydaoimpl

public class categorydaoimpl implements categorydao {     private sessionfactory sessionfactory;      public void setsessionfactory(sessionfactory sf){         this.sessionfactory = sf;     }  ...     @suppresswarnings("unchecked")     @override     public list<kpi> getkpisforcategory(int cat) {         session session = this.sessionfactory.getcurrentsession();         criteria criteria = session.createcriteria(kpi.class).add(restrictions.eq("category_id",cat));         return criteria.list();     } } 

categoryserviceimpl

 @service     public class categoryserviceimpl implements categoryservice {          private categorydao categorydao;          public void setcategorydao(categorydao dao) {             this.categorydao = dao;         } ...             @override         public list<kpi> listkpisforcategory(int cat) {             system.out.println("in service method");             return this.categorydao.getkpisforcategory(cat);         }     } 

jsp

<c:if test="${!empty listcategories}">     <table class="tg">         <tr>             <th width="80">category id</th>             <th width="120">category name</th>         </tr>         <c:foreach items="${listcategories}" var="category">         <tr>             <td>${category.id}</td>             <td>${category.categoryname}</td>             <td>                 <table class="tg">                     <tr>                         <th>kpi name</th>                     </tr>                     <tr>                      <c:foreach items="${category.kpis }" var="kpi">                         <td>${category.id}                         <td>${kpi.kpiname }</td>                     </c:foreach>                     </tr>                 </table>             </td>         </tr>         </c:foreach>     </table>     </c:if> 

no matter do, end nested table being empty, , child query never fires (which can tell due high tech logging!). missing? (sorry wall of text...)

thanks @naros's comment, able working. in categorydaoimpl class, added code listcategories() method populate kpi list in category object:

@suppresswarnings("unchecked")     @override     public list<category> listcategories() {         system.out.println("dao impl list categories");         session session = this.sessionfactory.getcurrentsession();         list<category> categorylist = session.createquery("from category").list();          (category c : categorylist) {             list<kpi> kpilist = getkpisforcategory(c.getid());             c.setkpis(kpilist);         }         return categorylist;     } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -