IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

Servlet hibernate Distinct


Sujet :

Servlets/JSP Java

  1. #21
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci infiniment j'ai remis le code que j'ai déjà supprimer parce ce que c'est important et je mets mon objet clients en session. voici le code de la servlet commande

    if (action.equals("new")) {
    List<Client> clients = null;
    Query q = sessionDb.createQuery("select distinct (c.nom) from Client c");
    clients = q.list();
    session.setAttribute("clients", clients);

  2. #22
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    ça fonctionne alors ?

  3. #23
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    malheureusement non

  4. #24
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    Est-ce que tu as réussi à voir quel est le résultat de la requête

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    select distinct (c.nom) from Client c
    il faut que tu trouves un moyen d'afficher le résultat de la requête ou de le voir en mode débug

    Essaies donc de trouver que vaut clients quand tu fais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    clients = q.list();

  5. #25
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci la requête fonctionne très bien elle affiche tous les clients sans répétition on mode débogage mais après il m'affiche cette erreur

    org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/commande/new.jsp at line 48

    45: <select name="client_id">
    46: <option value=""></option>
    47: <c:forEach var="client" items="${clients}" varStatus="loopStatus">
    48: <option value="${client.id}">${client.nom}</option>
    49: </c:forEach>
    50: </select>
    51:


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    servlets.commande.Commande.gotoPage(Commande.java:466)
    servlets.commande.Commande.doGet(Commande.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

  6. #26
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    c'est normal dans ta requête tu ne fais que récupérer le nom de tous les clients et non pas leur id !!
    donc tu ne peux pas faire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <option value="${client.id}">
    il faut que dans ta requête HQL tu récupères également l'id du client !

  7. #27
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci j'ai changé ma requête j'ai ajouter l'id du client
    Query q = sessionDb.createQuery("select distinct (c.nom), c.id from Client c");
    mais j'ai toujours le même problème

    org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/commande/new.jsp at line 48

    45: <select name="client_id">
    46: <option value=""></option>
    47: <c:forEach var="client" items="${clients}" varStatus="loopStatus">
    48: <option value="${client.id}">${client.nom}</option>
    49: </c:forEach>
    50: </select>
    51:


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    servlets.commande.Commande.gotoPage(Commande.java:466)
    servlets.commande.Commande.doGet(Commande.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

  8. #28
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    est-ce que tu peux afficher quel est le retour de la requête ?
    ET aussi la stack trace complète ?

  9. #29
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci pour vos réponse, j'ai exécuté l'application en mode débogage et le retour de la reqête est
    [[Ljava.lang.Object;@1be513c, [Ljava.lang.Object;@1c74f8d, [Ljava.lang.Object;@37b90c, [Ljava.lang.Object;@55cf3f, [Ljava.lang.Object;@1996bbd, [Ljava.lang.Object;@1707653, [Ljava.lang.Object;@686cea, [Ljava.lang.Object;@1c68e73, [Ljava.lang.Object;@b245dc, [Ljava.lang.Object;@87400, [Ljava.lang.Object;@f7cbd1, [Ljava.lang.Object;@661532]
    et pour l'erreur

    org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/commande/new.jsp at line 48

    45: <select name="client_id">
    46: <option value=""></option>
    47: <c:forEach var="client" items="${clients}" varStatus="loopStatus">
    48: <option value="${client.id}">${client.nom}</option>
    49: </c:forEach>
    50: </select>
    51:


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    servlets.commande.Commande.gotoPage(Commande.java:466)
    servlets.commande.Commande.doGet(Commande.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    cause m�re

    java.lang.NumberFormatException: For input string: "id"
    java.lang.NumberFormatException.forInputString(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    javax.el.ArrayELResolver.coerce(ArrayELResolver.java:153)
    javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
    javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
    org.apache.el.parser.AstValue.getValue(AstValue.java:118)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
    org.apache.jsp.jsp.commande.new_jsp._jspx_meth_c_005fforEach_005f0(new_jsp.java:301)
    org.apache.jsp.jsp.commande.new_jsp._jspService(new_jsp.java:225)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    servlets.commande.Commande.gotoPage(Commande.java:466)
    servlets.commande.Commande.doGet(Commande.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

  10. #30
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    si tu fais une requete SQL directement sur ta base qu'est ce que tu obtiens comme resultat ?
    parce que avec les références de tes objets on ne va pas pouvoir analyser

    En tout cas il semble que un des id ne soit pas un integer.

    Je pense surtout que c'est ta façon de renvoyer ta liste d'objet Client qui pose problème.
    Tu peux faire le test suivant stp :

    tu supprimes dans ta jsp la partie:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    value="${client.id}"
    et tu la remplaces provisoirement par

    normalement ta pages doit s'afficher et dans ta liste de choix tu devrais avoir

    en premier le nom du premier client , puis l'id du premier client etc

    est-ce que tu peux me confirmer ça stp et m'envoyer le retour de la requête² SQL directement sur la base de données ?

  11. #31
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci pour vos réponses si j'exécute la requête j'obtiens toute la liste des clients et pour l'id est integer incrémentale, j'ai remplacé le code tu m'indiques mais toujours ca fonctionne pas voici l'erreur que j'obtiens
    org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/commande/new.jsp at line 48

    45: <select name="client_id">
    46: <option value=""></option>
    47: <c:forEach var="client" items="${clients}" varStatus="loopStatus">
    48: <option value="">${client.nom}</option>
    49: </c:forEach>
    50: </select>
    51:


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    servlets.commande.Commande.gotoPage(Commande.java:466)
    servlets.commande.Commande.doGet(Commande.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    cause m�re

    java.lang.NumberFormatException: For input string: "nom"
    java.lang.NumberFormatException.forInputString(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    javax.el.ArrayELResolver.coerce(ArrayELResolver.java:153)
    javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
    javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
    org.apache.el.parser.AstValue.getValue(AstValue.java:118)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
    org.apache.jsp.jsp.commande.new_jsp._jspx_meth_c_005fforEach_005f0(new_jsp.java:301)
    org.apache.jsp.jsp.commande.new_jsp._jspService(new_jsp.java:225)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    servlets.commande.Commande.gotoPage(Commande.java:466)
    servlets.commande.Commande.doGet(Commande.java:78)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

  12. #32
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    donc je pense que ton problème peut venir du fait que ta liste n'est pas correctement remplis
    Il faut y mettre des objets Clients

  13. #33
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci pour vos réponse pourriez vous m'indiquez comment faire?

  14. #34
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    tu devrais faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    List<Client> result = new ArrayList<Client>();
    Client clientResult = null;
    for (int i = 0;i<clients.size()-2;i = i+1){
      clientResult = new Client();
      clientResult.setId(new Integer(clients.get(i+1)));
      clientResult.setNom(clients.get(i));
      result.add(clientResult);
    }
    et enfin
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    request.setAttibute("clients",result);

  15. #35
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci pour votre réponse mais j'ai pas compris le clients dans ce code
    for (int i = 0;i<clients.size()-2;i = i+1)
    ça veut dire quoi et comment je peux le déclarer et est ce que je ne besoin pas de la requête? merci infiniment .

  16. #36
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    la variables clients c'est celle que tu as déjà crée

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    clients = q.list();

  17. #37
    Nouveau membre du Club
    Inscrit en
    Janvier 2011
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 114
    Points : 30
    Points
    30
    Par défaut
    merci pour vos réponses vous pouvez me dire où exactement je peux mettre le code que vous m'avez donnez voici mon code

    if (action.equals("new")) {
    List<Client> clients = null;
    Query q = sessionDb.createQuery("select distinct (c.nom), c.id from Client c");
    clients = q.list();
    request.setAttribute("clients", clients);

  18. #38
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    
    if (action.equals("new")) {
    			List<String> clients = null; //ici je pense que ce sont des strings
    			Query q = sessionDb.createQuery("select distinct (c.nom), c.id from Client c");
    			clients = q.list();
    
    List<Client> result = new ArrayList<Client>();
    Client clientResult = null;
    for (int i = 0;i<clients.size()-2;i = i+1){
      clientResult = new Client();
      clientResult.setId(new Integer(clients.get(i+1)));
      clientResult.setNom(clients.get(i));
      result.add(clientResult);
    }
    
    
    			request.setAttribute("result", clients); 			 		
    
    }
    essaie qque chose comme ça

  19. #39
    Membre éprouvé Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Points : 1 161
    Points
    1 161
    Par défaut
    Bonjour

    est-ce que ta mise à jour fonctionne ?

Discussions similaires

  1. Coordination entre servlet + Hibernate
    Par abdoulfall dans le forum Autres
    Réponses: 10
    Dernier message: 20/02/2012, 09h27
  2. Erreur servlet hibernate: id to load is required for loading
    Par salma309 dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 14/03/2011, 15h26
  3. problème de servlet et hibernate
    Par meryeminfo dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 04/09/2009, 15h28
  4. Réponses: 0
    Dernier message: 09/10/2007, 03h10
  5. Problème de lancement Servlet avec Hibernate
    Par jamy79 dans le forum Hibernate
    Réponses: 2
    Dernier message: 24/11/2006, 11h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo