mais le problème c'est que je peux pas toucher à la structure de la table.
J'ai fais exactement ce que vous avez dit avec :
<generator class="assigned" /> sur un champs unique.
Mais quand je lance une requete pas de resultat :(
Version imprimable
mais le problème c'est que je peux pas toucher à la structure de la table.
J'ai fais exactement ce que vous avez dit avec :
<generator class="assigned" /> sur un champs unique.
Mais quand je lance une requete pas de resultat :(
faut voir
- le mapping
- la structure
- la requete hql
- le sql généré par hibernate (show_sql à true dans la config)
voila la structure de ma table :
Sachant que les types sont proprietaire à hyperfile.Code:
1
2
3
4
5 UtilCode : text UtilPrenom : text UtilNom : text UtilPwd : text UtilGpe : text
Ma classe :
Mon fichier hbm.xml :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 public class Utilisateur implements java.io.Serializable { private String utilcode; private String utilprenom; private String utilnom; private String utilpwd; private String utilgpe; public Utilisateur() { } public Utilisateur(String utilcode, String utilprenom, String utilnom, String utilpwd, String utilgpe) { this.utilcode = utilcode; this.utilprenom = utilprenom; this.utilnom = utilnom; this.utilpwd = utilpwd; this.utilgpe = utilgpe; } /** * @return the utilcode */ public String getUtilcode() { return utilcode; } /** * @param utilcode the utilcode to set */ public void setUtilcode(String utilcode) { this.utilcode = utilcode; } /** * @return the utilprenom */ public String getUtilprenom() { return utilprenom; } /** * @param utilprenom the utilprenom to set */ public void setUtilprenom(String utilprenom) { this.utilprenom = utilprenom; } /** * @return the utilnom */ public String getUtilnom() { return utilnom; } /** * @param utilnom the utilnom to set */ public void setUtilnom(String utilnom) { this.utilnom = utilnom; } /** * @return the utilpwd */ public String getUtilpwd() { return utilpwd; } /** * @param utilpwd the utilpwd to set */ public void setUtilpwd(String utilpwd) { this.utilpwd = utilpwd; } /** * @return the utilgpe */ public String getUtilgpe() { return utilgpe; } /** * @param utilgpe the utilgpe to set */ public void setUtilgpe(String utilgpe) { this.utilgpe = utilgpe; } }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 18 juin 2009 11:44:53 by Hibernate Tools 3.2.1.GA --> <hibernate-mapping> <class name="com.outilrequete.model.Utilisateur" table="R_utilisateur" catalog="Base"> <id name="utilcode" type="String"> <column name="UtilCode" /> <generator class="assigned" /> </id> <property name="utilprenom" type="string"> <column name="UtilPrenom" length="50" not-null="true" /> </property> <property name="utilnom" type="string"> <column name="UtilNom" length="50" not-null="true" /> </property> <property name="utilpwd" type="string"> <column name="UtilPwd" length="30" not-null="true" /> </property> <property name="utilgpe" type="string"> <column name="UtilGpe" length="30" not-null="true" /> </property> </class> </hibernate-mapping>
il manque:
- l'appel que tu fait
- le sql généré par hibernate
La methode de j'utilise :
Pour sql ça me genere aucun meme si :Code:
1
2
3
4
5
6
7
8
9
10
11
12 public List<Utilisateur> findAll() { try { org.hibernate.Transaction tx = session.beginTransaction(); Query query = (Query) session.createQuery("from Utilisateur"); List<Utilisateur> userEtudiant = (List<Utilisateur>) query.getResultList(); return userEtudiant; } catch (RuntimeException re) { re.printStackTrace(); return new ArrayList<Utilisateur>(); } }
<property name="hibernate.show_sql">true</property>
tu lance ton application avec java ou javaw.exe? Si tu ne vois rien dans la console, tu ne vois probablement pas non plus l'exception qui te fait renvoyer une liste vide.
moi je teste ma methode dans une jsp
ça me retourne "null"Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 UtilisateurDaoImp usi=new UtilisateurDaoImp(); try{ List utilisateur=usi.findAll(); int utilisateursize=utilisateur.size(); out.print("<tr><th><b>Numero</b></th><th><b>Question</b></th></tr>"); for (int i = 0; i < utilisateursize; i++) { Utilisateur qs = (Utilisateur) utilisateur.get(i); out.print("<tr>"); out.print("<td><b>" + qs.getUtilcode() + "</b></td>"); out.print("<td><b>" + qs.getUtilnom() + "</b></td>"); out.print("</tr>"); } }catch(Exception e){ out.print(e.getMessage()); }
faut regarder les logs de ton conteneur, tu y trouvera l'exception et tous les messages de démarrage d'hibernate.
j ai appler la methode directement de ma couche dao et voila l exception :
type Rapport d'exception
Message
DescriptionLe serveur a rencontré une erreur interne () qui l'a empêché de remplir cette requête.
Exception
javax.servlet.ServletException: java.lang.ExceptionInInitializerError
Cause racine
java.lang.ExceptionInInitializerError
Cause racine
org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(UtilCode)]
c'est "string" pas "String" dans le mapping.
Merci Beaucoup j'ai reussit l'extraction du données de ma base