j'ai crée un entity beans Produit apres
---------------------------------------------------
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 package my; import javax.ejb.Remote; /** * * @author Abdelghani */ @Remote public interface EcchangeProduitRemote { public void addProduit(Produit produit); public Produit getProduit(int id); public void updateCustomer(Produit 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 package my; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author Abdelghani */ @Stateless public class EcchangeProduitBean implements EcchangeProduitRemote { @PersistenceContext(unitName = "stockManager") protected EntityManager em; public Produit getProduit(int id) { Produit p = em.find(Produit.class, new Integer(id)); return p; } public void updateCustomer(Produit p) { em.merge(p); } public void addProduit(Produit produit) { em.persist(produit); } // Add business logic below. (Right-click in editor and choose // "EJB Methods > Add Business Method" or "Web Service > Add Operation") }
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 produitaction; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import my.EcchangeProduitRemote; import my.Produit; /** * * @author Abdelghani */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws NamingException { try{ Context ctx = new InitialContext(); EcchangeProduitRemote bean = (EcchangeProduitRemote) ctx.lookup("my.EcchangeProduitRemote"); Produit c = bean.getProduit(2); System.out.println(c); Produit a = new Produit(); a.setId("10"); a.setTitle("fafa"); a.setDescription("coucou"); bean.addProduit(a); System.out.println("ddddddddddddd"); System.out.println("Retrieved produit: " + c.getDescription()); } catch(Exception E){ } } }
Partager