Bonjour,
Un nullpointer exception est jeté lors de l'éxécusion. pq
Merci
Application
classe Employee
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
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 package Launcher; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import com.sun.xml.internal.ws.developer.Stateful; import model.Employee; public class Application { /** * @param args */ @PersistenceContext(unitName="magasin") public static void main(String[] args) { OrgStructure b = new OrgStructure(); System.out.println(b.findEmployee(1)); } public void make(){ } } @Stateful class OrgStructure{ private static final String ORG_QUERY = "SELECT idEmployee FROM employee " + "WHERE idEmployee = ?"; @PersistenceContext(unitName="magasin") EntityManager em; private Employee c = null; public Employee findEmployee(int id){ c = (Employee) em.createNativeQuery(ORG_QUERY, model.Employee.class) .setParameter(1, id).getSingleResult(); System.out.println(c.getNom()); return c; } }
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
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 package model; import java.io.Serializable; import java.lang.String; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Transient; /** * Entity implementation class for Entity: Employee * */ @Entity public class Employee implements Serializable { private static final long serialVersionUID = 1L; @Id private java.lang.Integer idEmployee; private String Nom; @Transient private String Matricule; public Employee() { super(); } public java.lang.Integer getIdEmployee() { return idEmployee; } public void setIdEmployee(java.lang.Integer idEmployee) { this.idEmployee = idEmployee; } public String getNom() { return this.Nom; } public void setNom(String Nom) { this.Nom = Nom; } public String getMatricule() { return Matricule; } public void setMatricule(String matricule) { Matricule = matricule; } public String toString(){ StringBuilder v = new StringBuilder(); v.append("Numéro : "+this.getIdEmployee() + " Nom : " + this.getNom()); return v.toString(); } }
Partager