JSF / hibernate hql does not show results

0

I have an HQL to extract data from a table that has the same user ID that I'm clicking

my bean is:

public void setViewUser () throws IOException {

    UserDAOImpl dao = new UserDAOImpl();  

    User user = dao.findById(id_user);
    id_user = user.getId_user();
    nom = user.getNom();
    prenom = user.getPrenom();
    mail = user.getMail();
    dette = user.getDette();
    telephone = user.getTelephone();
    adressePostal =user.getAdressePostal();
    nombre_objet_reserve = user.getNombre_objet_reserve();
    nombre_objet_loue =user.getNombre_objet_loue();  
    FacesContext.getCurrentInstance().getExternalContext().redirect("Compte_client.xhtml");

}

private serviceMethods serviceMethods = new serviceMethods();
List<Pl> list = serviceMethods.ListPl(id_user);
@SuppressWarnings("unchecked")
List<Pl> pllist = (List<Pl>)(Object) list;

and my serviceMethods is:

@SuppressWarnings("unchecked")
public List<Pl> ListPl(Integer id) {

                String queryString = "from Pl f where f.user= :id) ";

             Session sess = HibernateUtil.openSession();
             Query query = sess.createQuery(queryString);
             query.setParameter("id", id);
             List<Pl> listObject = (List<Pl>) query.list();
              sess.getTransaction();
              sess.close();
              return listObject;

            }

my xhtml is:

<h:dataTable class="table table-bordered" id="dataTable" width="100%" cellspacing="0" value="#{AffichUserBean.pllist}" var="t">

        <h:column><f:facet name="header">idres</f:facet>#{t.coutFinal}</h:column>

      <h:column><f:facet name="header">deadline</f:facet>#{t.caution_produit}</h:column>
         <h:column><f:facet name="header">defauts</f:facet>#{t.defauts}</h:column>


          </h:dataTable>

I get the hql in the console but I only get the result for the second one and not the first:

  

2018-03-19T15: 12: 39.633 + 0100 | Infos: Hibernate: select pl0_.num_series as num_seri1_1_, pl0_.idproduit as idprodui2_1_,   pl0_.id_user as id_user3_1_, pl0_.date_debut_location as date_deb4_1_,   pl0_.date_fin_location as date_fin5_1_, pl0_.defauts as defauts6_1_,   pl0_.reserve as reserve7_1_, pl0_.prix_location_jour as prix_loc8_1_,   pl0_.caution_produit as caution_9_1_, pl0_.of the ace of10_1_ from pl   pl0_ where pl0_.id_user =?

     

2018-03-19T15: 12: 39.651 + 0100 | Infos: Hibernate: select user0_.id_user as id_user1_4_0_, user0_.nom as nom2_4_0_, user0_.mail   as mail3_4_0_, user0_.password as password4_4_0_, user0_.dette as   dette5_4_0_, user0_.photo as photo6_4_0_, user0_.telephone as   telephon7_4_0_, user0_.prenom as prenom8_4_0_, user0_.adresse_postale   as adresse_9_4_0_, user0_.nombre_objet_reserve as nombre_10_4_0_,   user0_.name_object_loue as name_11_4_0_ from user user0_ where   user0_.id_user =?

Mapping the first entity

   

  <meta attribute = "class-description">
     This class contains the user detail. 
  </meta>

  <id name = "id_user" type = "int" column = "id_user">
         <generator class="increment" />

  </id>

  <property name = "nom" column = "nom" type = "string"/>
  <property name = "mail" column = "mail" type = "string"/>
  <property name = "password" column = "password" type = "string"/>
  <property name = "dette" column = "dette" type = "int"/>
  <property name = "photo" column = "photo" type = "string"/>
  <property name = "telephone" column = "telephone" type = "string"/>
  <property name = "prenom" column = "prenom" type = "string"/>
  <property name = "adressePostal" column = "adresse_postale" type = "string"/>
  <property name = "nombre_objet_reserve" column = "nombre_objet_reserve" type = "int"/>
  <property name = "nombre_objet_loue" column = "nombre_objet_loue" type = "int"/>

the mapping of the second entity

<id name = "num_serie" type = "int" column = "num_serie">
         <generator class="increment" />

  </id>

   <many-to-one name="produit_loue" class="com.serveurweb.location.doa.entities.Produit"
        column="idproduit" unique="true"  lazy ="false" not-null="true"
        cascade="all" />
   <many-to-one name="user" class="com.serveurweb.location.doa.entities.User"
        column="id_user" unique="true" lazy ="false" not-null="true"
        cascade="all" />

   <property name = "date_debut_location" column = "date_debut_location" type = "date"/>
   <property name = "date_fin_location" column = "date_fin_location" type = "date"/>
   <property name = "defauts" column = "defauts" type = "string"/>
   <property name = "reserve" column = "reserve" type = "int"/>
   <property name = "prix_location_jour" column = "prix_location_jour" type = "int"/>
   <property name = "caution_produit" column = "caution_produit" type = "int"/>
   <property name = "del" column = "del" type = "int"/>

I do not know, but when I try the query with an identification number, I get the result I want, but when I use it: id I do not get results.

 public static void main(String[] args) throws Exception { 
 session.getTransaction().begin(); 
 Query query = session.createQuery("from Pl f where f.user.id_user= 3");
 @SuppressWarnings("unchecked") 
 List<Pl>pl = (List<Pl>) query.list(); 
 for(Pl l : pl) System.out.println(l.getNum_serie()); 
 session.getTransaction().commit();
 HibernateUtil.close();}
    
asked by ThePassenger 19.03.2018 в 15:22
source

0 answers