Bonsoir .
Je travaille sur Netbeans 7.1 dans le cadre d'un projet sur les EJB3.
J'ai cree une Base de donnee vide (ou je veux mette mes tables).
J'ai cree ma classe entite et j'ai mentionnee le data-source,
de meme j'ai cree le session bean:
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 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; /** * * @author user */ @Entity(name="CompteBancaire") @Table(name = "CompteBancaire") public class CompteBancaire implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "id", nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private String id; public String getId() { return id; } public void setId(String id) { this.id = id; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.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 CompteBancaire)) { return false; } CompteBancaire other = (CompteBancaire) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "entities.CompteBancaire[ id=" + id + " ]"; } @Column(name = "proprietaire") String owner; @Column(name = "solde") int solde; public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public int getSolde() { return solde; } public void setSolde(int solde) { this.solde = solde; } public CompteBancaire(String id, String owner, int solde) { this.id = id; this.owner = owner; this.solde = solde; } public CompteBancaire() { } }
Lorsque je deploie le projet ,ma table "Compte bancaire" ne se cree pas , c'ei le probleme SVP ?
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 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package session; import entities.CompteBancaire; import java.util.List; import javax.ejb.Stateless; import javax.ejb.LocalBean; import javax.ejb.TransactionManagement; import javax.ejb.TransactionManagementType; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author user */ @Stateless @TransactionManagement(TransactionManagementType.CONTAINER) @LocalBean public class GestionnaireDeBanque { @PersistenceContext(unitName = "GestionnaireDeBanque-ejbPU") private EntityManager em; public void creerCompte(CompteBancaire c) { c=new CompteBancaire(); em.persist(c); } public List<CompteBancaire> getAllComptes() { return null; } public void persist(Object object) { em.persist(object); } public void creerComptesTest() { creerCompte(new CompteBancaire("c1","John Lennon", 150000)); creerCompte(new CompteBancaire("c2","Cartney", 950000)); creerCompte(new CompteBancaire("C3","Ringo Starr", 20000)); creerCompte(new CompteBancaire("c4","Georges Harrisson", 100000)); } }
Voici le fichier persistance.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="GestionnaireDeBanque-ejbPU" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>Banque</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> </properties> </persistence-unit> </persistence>
Partager