j'ai une fonction qui doit recuperer un enregistrement d'une base de données .
je travaille avec hibernate 3 du coup je trouve plus la methode find(String arg0) j'ai essayé alors la methode load mais celle ci me retourne NullPointerException
Version imprimable
j'ai une fonction qui doit recuperer un enregistrement d'une base de données .
je travaille avec hibernate 3 du coup je trouve plus la methode find(String arg0) j'ai essayé alors la methode load mais celle ci me retourne NullPointerException
Il faut croire qu'à l'identifiant que tu utilises avec ta méthode load ne correspond aucun objet en base.
Montre nous ton code.
desole je vien de revoir ma classe en effet dans la base le client à un id composé d'un radical et d'un num d'itentite alors hibernate à mapper la classe physiqueId dont les champs sont les deux identifiant .
j'aimerais savoir comment faire une selection à la base d'un seul identifiant soit le radical ou le num d'itentite
code de la classe client Physique
code de la classe de la cle compositeCode:
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
90
91
92
93
94
95
96
97
98 package cls; // Generated 8 juil. 2009 10:49:24 by Hibernate Tools 3.2.4.GA /** * Physique generated by hbm2java */ public class Physique implements java.io.Serializable { private PhysiqueId id; private Client client; private String nom; private String prenom; private String adresse; private String ville; private String codepostal; private String tel; public Physique() { } public Physique(PhysiqueId id, Client client, String nom, String prenom, String adresse, String ville, String codepostal, String tel) { this.id = id; this.client = client; this.nom = nom; this.prenom = prenom; this.adresse = adresse; this.ville = ville; this.codepostal = codepostal; this.tel = tel; } public PhysiqueId getId() { return this.id; } public void setId(PhysiqueId id) { this.id = id; } public Client getClient() { return this.client; } public void setClient(Client client) { this.client = client; } public String getNom() { return this.nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return this.prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public String getAdresse() { return this.adresse; } public void setAdresse(String adresse) { this.adresse = adresse; } public String getVille() { return this.ville; } public void setVille(String ville) { this.ville = ville; } public String getCodepostal() { return this.codepostal; } public void setCodepostal(String codepostal) { this.codepostal = codepostal; } public String getTel() { return this.tel; } public void setTel(String tel) { this.tel = tel; } }
voila le fichier de mapping de la classe physiqueCode:
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 package cls; // Generated 8 juil. 2009 10:49:24 by Hibernate Tools 3.2.4.GA /** * PhysiqueId generated by hbm2java */ public class PhysiqueId implements java.io.Serializable { /** * */ private static final long serialVersionUID = 986132205814515151L; private int radical; private String cin; public PhysiqueId() { } public PhysiqueId(int radical, String cin) { this.radical = radical; this.cin = cin; } public int getRadical() { return this.radical; } public void setRadical(int radical) { this.radical = radical; } public String getCin() { return this.cin; } public void setCin(String cin) { this.cin = cin; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof PhysiqueId)) return false; PhysiqueId castOther = (PhysiqueId) other; return (this.getRadical() == castOther.getRadical()) && ((this.getCin() == castOther.getCin()) || (this.getCin() != null && castOther.getCin() != null && this.getCin().equals( castOther.getCin()))); } public int hashCode() { int result = 17; result = 37 * result + this.getRadical(); result = 37 * result + (getCin() == null ? 0 : this.getCin().hashCode()); return result; } }
et merci pour ta precieuse coopération.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 <?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 8 juil. 2009 10:49:25 by Hibernate Tools 3.2.4.GA --> <hibernate-mapping> <class name="cls.Physique" table="physique" catalog="instruction_credits"> <composite-id name="id" class="cls.PhysiqueId"> <key-property name="radical" type="int"> <column name="radical" /> </key-property> <key-property name="cin" type="string"> <column name="cin" length="20" /> </key-property> </composite-id> <many-to-one name="client" class="cls.Client" update="false" insert="false" fetch="select"> <column name="radical" not-null="true" /> </many-to-one> <property name="nom" type="string"> <column name="nom" length="45" not-null="true" /> </property> <property name="prenom" type="string"> <column name="prenom" length="45" not-null="true" /> </property> <property name="adresse" type="string"> <column name="adresse" length="45" not-null="true" /> </property> <property name="ville" type="string"> <column name="ville" length="45" not-null="true" /> </property> <property name="codepostal" type="string"> <column name="codepostal" length="45" not-null="true" /> </property> <property name="tel" type="string"> <column name="tel" length="45" not-null="true" /> </property> </class> </hibernate-mapping>
Et en passant à load un PhysiqueId initialisé avec les bonnes valeurs ?
s'il vous plait je ne saurais le faire je ne suisque debutant dans hibernate si vous pouvez me donne un indice .
Code:
1
2
3
4
5 //mettre les bonnes valeurs de ton id PhysiqueId id = new PhysiqueId(2, "aaa"); Physique tonObjet = taSession.load(Physique.class, id);
si je me permet.
j'aimerais savoir comment faire pour rechercher un client juste par son num d'itentite et que le radical nous n'est pas fournie .
est ce qu'on doit refaire un constructour pour la classe Physiqueid
et re-merci.
Je pense que dans ce cas, il te faudra passer par une requête HQL ou Criteria.
Je crains bien que ça soit trops demandé.
pourriez vous m'expliquer un peu .j'ai pas de bon tutoriel sous la main ou c'est juste ma casrole qui ne serre plus à rien.:ccool:
http://docs.jboss.org/hibernate/stab...r/html_single/
Ce sera un bon début pour commencer.