Salut
voila j'ai un problème d’ajout est je ne sais pas vraiment d'ou vient l'erreur
j'ai crée une Entity Bean Personne
puis j'ai crée un Manger bean pour avec une fonction d'ajout
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 @Entity public class Personne implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String nomComplet; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getNomComplet() { return nomComplet; } public void setNomComplet(String nomComplet) { this.nomComplet = nomComplet; } @Override public int hashCode() { int hash = 0; hash += (int) id; 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 Personne)) { return false; } Personne other = (Personne) object; if (this.id != other.id) { return false; } return true; } @Override public String toString() { return "entites.Personne[id=" + id + "]"; } }
mais rien ne marche
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 @ManagedBean @RequestScoped public class indexBean { @PersistenceContext(unitName="TestSimplePU") EntityManager em; private String message="En attente"; public indexBean() { } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public void ajouter(){ try { Personne personne= new Personne(); personne.setNomComplet("Super Man"); em.persist(personne); message="Ajout bin fait "; } catch (Exception e) { message = "Erreur "+e; } } }j'ai ce message d'erreur javax.persistence.TransactionRequiredException
merci d’avance
Partager