salut,
j'ai créer une application JEE (entreprise application)avec netbeans qui traite ces deux notions EJB3 et glassfish
mais mon problème est comment intégrer la notion d'hibernate/JPA
je suis un cours avec exemple sur le net pour que je puisse terminer cette application
mon application est subdivise en deux partie : clientGPE et projetGPE-ejb
dans projetGPE-ejb
je creer projetjpe.ejb.entite et projetjpe.ejb.session
je vous donne un exemple de class qui se trouve dans projetjpe.ejb.entite
et un exemple pour projetjpe.ejb.session
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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 package projetgpe.ejb.entites; import java.io.Serializable; import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; /** * * @author lefennec */ @Entity @Table(name = "ENSEIGNANT") @NamedQueries({@NamedQuery(name = "Enseignant.findByMatriculeens", query = "SELECT e FROM Enseignant e WHERE e.matriculeens = :matriculeens"), @NamedQuery(name = "Enseignant.findByNomens", query = "SELECT e FROM Enseignant e WHERE e.nomens = :nomens"), @NamedQuery(name = "Enseignant.findByPrenomens", query = "SELECT e FROM Enseignant e WHERE e.prenomens = :prenomens"), @NamedQuery(name = "Enseignant.findBySexeens", query = "SELECT e FROM Enseignant e WHERE e.sexeens = :sexeens"), @NamedQuery(name = "Enseignant.findByGradeens", query = "SELECT e FROM Enseignant e WHERE e.gradeens = :gradeens"), @NamedQuery(name = "Enseignant.findByFonctionens", query = "SELECT e FROM Enseignant e WHERE e.fonctionens = :fonctionens")}) public class Enseignant implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "MATRICULEENS", nullable = false) private String matriculeens; @Column(name = "NOMENS") private String nomens; @Column(name = "PRENOMENS") private String prenomens; @Column(name = "SEXEENS") private String sexeens; @Column(name = "GRADEENS") private String gradeens; @Column(name = "FONCTIONENS") private String fonctionens; @ManyToMany(mappedBy = "matriculeensCollection") private Collection<Cours> codecoursCollection; public Enseignant() { } public Enseignant(String matriculeens) { this.matriculeens = matriculeens; } public String getMatriculeens() { return matriculeens; } public void setMatriculeens(String matriculeens) { this.matriculeens = matriculeens; } public String getNomens() { return nomens; } public void setNomens(String nomens) { this.nomens = nomens; } public String getPrenomens() { return prenomens; } public void setPrenomens(String prenomens) { this.prenomens = prenomens; } public String getSexeens() { return sexeens; } public void setSexeens(String sexeens) { this.sexeens = sexeens; } public String getGradeens() { return gradeens; } public void setGradeens(String gradeens) { this.gradeens = gradeens; } public String getFonctionens() { return fonctionens; } public void setFonctionens(String fonctionens) { this.fonctionens = fonctionens; } public Collection<Cours> getCodecoursCollection() { return codecoursCollection; } public void setCodecoursCollection(Collection<Cours> codecoursCollection) { this.codecoursCollection = codecoursCollection; } @Override public int hashCode() { int hash = 0; hash += (matriculeens != null ? matriculeens.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Enseignant)) { return false; } Enseignant other = (Enseignant) object; if ((this.matriculeens == null && other.matriculeens != null) || (this.matriculeens != null && !this.matriculeens.equals(other.matriculeens))) { return false; } return true; } @Override public String toString() { return "projetgpe.ejb.entites.Enseignant[matriculeens=" + matriculeens + "]"; } }
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 projetgpe.ejb.sessions; import java.util.List; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import projetgpe.ejb.entites.Enseignant; /** * * @author lefennec */ @Stateless public class EnseignantFacade implements EnseignantFacadeLocal, EnseignantFacadeRemote { @PersistenceContext private EntityManager em; public void create(Enseignant enseignant) { em.persist(enseignant); } public void edit(Enseignant enseignant) { em.merge(enseignant); } public void remove(Enseignant enseignant) { em.remove(em.merge(enseignant)); } public Enseignant find(Object id) { return em.find(projetgpe.ejb.entites.Enseignant.class, id); } public List<Enseignant> findAll() { return em.createQuery("select object(o) from Enseignant as o").getResultList(); } public void enregistrerEnseignant(String matricule, String nom, String prenom, String sexe, String grade, String fonction) { Enseignant en=new Enseignant(); en.setMatriculeens(matricule); en.setNomens(nom); en.setPrenomens(prenom); en.setSexeens(sexe); en.setGradeens(grade); en.setFonctionens(fonction); em.persist(en); em.flush(); } }
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 package projetgpe.ejb.sessions; import java.util.List; import javax.ejb.Local; import projetgpe.ejb.entites.Enseignant; /** * * @author lefennec */ @Local public interface EnseignantFacadeLocal { void create(Enseignant enseignant); void edit(Enseignant enseignant); void remove(Enseignant enseignant); Enseignant find(Object id); List<Enseignant> findAll(); void enregistrerEnseignant(String matricule, String nom, String prenom, String sexe, String grade, String fonction); }mais avec d'autre cours je constater que les tables et les attributs ne doivent pas creer manuellement dans la base de donne mais avec JPA
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 package projetgpe.ejb.sessions; import java.util.List; import javax.ejb.Remote; import projetgpe.ejb.entites.Enseignant; /** * * @author lefennec */ @Remote public interface EnseignantFacadeRemote { void create(Enseignant enseignant); void edit(Enseignant enseignant); void remove(Enseignant enseignant); Enseignant find(Object id); List<Enseignant> findAll(); void enregistrerEnseignant(String matricule, String nom, String prenom, String sexe, String grade, String fonction); }
je veux savoir comment et aussi comment consulter les attributs d'une telle table
je vous donne un exemple de class qui est enseignant qui a des attributs qui sont les même dans la base de donne
si vous avez besoin d'autre fichier n'hésite pas a me demander
merci d'avance
Partager