-->
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.  [ 5 posts ] 
Author Message
 Post subject: Viewing result of an inner join query in struts
PostPosted: Wed Nov 28, 2007 9:56 am 
Newbie

Joined: Wed Nov 28, 2007 9:42 am
Posts: 3
Hi everyone, I'm pretty new in Hibernate so I'm sorry if my question is trivial.
I got an action that does this:


Code:
   public ActionForward execute(ActionMapping mapping, ActionForm form,
         HttpServletRequest request, HttpServletResponse response) {
      
         List ordine = OrdiniManager.getInstance().list();
         request.setAttribute("ordine", ordine);

      return mapping.findForward("showNuoviOrdini");
      
   }


It calls the metod list() of a class called OrdiniManager, that does this:

Code:
public List list() throws HibernateException
{
    try {           
        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session session = sf.openSession();
        Transaction tx = session.beginTransaction();
       
        org.hibernate.Query q = session.createQuery("from Localita L inner join L.magazzinos M inner join M.ordineMagazzinos OM inner join OM.id.ordine O inner join O.cliente C where O.stato = 'in valutazione'");
       
        List list=q.list();
       
        tx.commit();
        session.flush();
        session.close();
        sf.close();
        return list;
                }
        catch (HibernateException e) {
            e.printStackTrace();
            return null;
           }   
}


I need to show the result of the query in a jsp page, but this won't work:

Code:
     <logic:iterate id="ordine" name="ordine">

   <tr class="riga_dati">
   <td>&nbsp;</td>
     <td>
        <bean:write name="ordine" property="O.idOrdine" />
   </td>
     <td>
        <bean:write name="ordine" property="C.idUtente" />
   </td>
     <td>
        <bean:write name="ordine" format="dd/MM/yyyy HH:mm" property="O.dataRicezione" />
   </td>
    <td>
        <bean:write name="ordine" format="dd/MM/yyyy" property="O.deadline" />
   </td>
     <td>
        <bean:write name="ordine" property="M.idMagazzino" />
   </td>
   <td>
        <bean:write name="ordine" property="O.priorita" />
   </td>
   </tr>
     </logic:iterate>


I think the problem is that I can't manage a query using "inner joins" as a simple query. No exception is throwed.
How can I solve it?
Thank you!
Roberto from Italy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 10:31 am 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
Set the Show-Sql to true in your config file. See what is the SQL actually it is trying to execute. It should help a bit to debug the problem.

_________________
Please rate if it helped


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 11:30 am 
Newbie

Joined: Wed Nov 28, 2007 9:42 am
Posts: 3
This is what it shows:

select localita0_.id_localita as id1_8_0_, magazzinos1_.id_magazzino as id1_9_1_, ordinemaga2_.id_ordine as id1_27_2_, ordinemaga2_.id_magazzino as id2_27_2_, ordine3_.id_ordine as id1_16_3_, cliente4_.id_utente as id1_14_4_, localita0_.cap as cap8_0_, localita0_.citta as citta8_0_, localita0_.provincia as provincia8_0_, localita0_.regione as regione8_0_, magazzinos1_.id_localita as id2_9_1_, magazzinos1_.id_ordine as id3_9_1_, magazzinos1_.nome as nome9_1_, magazzinos1_.indirizzo as indirizzo9_1_, magazzinos1_.id_localita as id2_0__, magazzinos1_.id_magazzino as id1_0__, ordinemaga2_.direzione as direzione27_2_, ordinemaga2_.id_magazzino as id2_1__, ordinemaga2_.id_ordine as id1_1__, ordine3_.id_consorzio as id2_16_3_, ordine3_.id_tipo as id3_16_3_, ordine3_.id_cliente as id4_16_3_, ordine3_.data_ricezione as data5_16_3_, ordine3_.stato as stato16_3_, ordine3_.deadline as deadline16_3_, ordine3_.priorita as priorita16_3_, ordine3_.tempo_di_scarico as tempo9_16_3_, cliente4_.fax as fax14_4_, cliente4_.p_iva as p3_14_4_ from dialogodb.localita localita0_ inner join dialogodb.magazzino magazzinos1_ on localita0_.id_localita=magazzinos1_.id_localita inner join dialogodb.ordine_magazzino ordinemaga2_ on magazzinos1_.id_magazzino=ordinemaga2_.id_magazzino inner join dialogodb.ordine ordine3_ on ordinemaga2_.id_ordine=ordine3_.id_ordine inner join dialogodb.cliente cliente4_ on ordine3_.id_cliente=cliente4_.id_utente where ordine3_.stato='in valutazione'


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 12:03 pm 
Newbie

Joined: Wed Nov 28, 2007 9:42 am
Posts: 3
I think the problem is not the query. If I test it into the MyEclipse's SQL Editor it works.
The problem is: how can I access to the objects resulting from the query?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 9:57 am 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
Check to see if the list is actually getting populated. I think it is probably getting an exception and returning a null. Put a break point after

[code]List list=q.list(); [/code]

_________________
Please rate if it helped


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.