Bonjour,
je suis entrain d'ecrire deux ejb, l'un pour stocker le produit et l'autre pour stocker l'entreprise.
L'objectif est de relier Entity entreprise et Entity Produit.
Le principe de fonctionnement est décrit comme suit :
inserer dans produit si seulement s'il existe deja dans entreprise(une sorte de clé etrangère)
mais j'ai cette exception :javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: entreprise.Entreprise2
Je ne comprends pas le probleme, pourtant j'ai importe l'ejb entreprise dans l'ejb entity
J'ai utilise eclipse kelper, jboss 4.2 et jre1.7.
Merci pour toute aide.
Voici le code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 package entity; import javax.ejb.Remote; @Remote public interface IProduit4 { void ajouter(Produit4 p); }
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 package entity; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class Produit4 implements Serializable{ @Id String id; String lib; int quantite; String ref; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getLib() { return lib; } public void setLib(String lib) { this.lib = lib; } public int getQuantite() { return quantite; } public void setQuantite(int quantite) { this.quantite = quantite; } public String getRef() { return ref; } public void setRef(String ref) { this.ref = ref; } @Override public String toString() { return "Produit [id=" + id + ", lib=" + lib + ", quantite=" + quantite + ", ref=" + ref + "]"; } public Produit4(String id, String lib, int quantite, String ref) { super(); this.id = id; this.lib = lib; this.quantite = quantite; this.ref = ref; } }
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 package entity; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import entreprise.Entreprise2; @Stateless public class ProduitBean implements IProduit4 { @PersistenceContext EntityManager em; @Override public void ajouter(Produit4 p) { // TODO Auto-generated method stub if(em.find(Entreprise2.class,p.getRef())!=null) em.persist(p); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 package entreprise; import javax.ejb.Remote; @Remote public interface IEntreprise { void ajouter(Entreprise2 entreprise); }
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 package entreprise; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Stateless public class EntrepriseBean implements IEntreprise { @PersistenceContext EntityManager em; @Override public void ajouter(Entreprise2 entreprise) { em.persist(entreprise); } }
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 package entreprise; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class Entreprise2 implements Serializable { @Id private String id; private String nom; @Override public String toString() { return "Entreprise [id=" + id + ", nom=" + nom + "]"; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public Entreprise2(String id, String nom) { super(); this.id = id; this.nom = nom; } }
Partager