KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > packaging > bean > Session1Bean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.packaging.bean;
8
9 import javax.ejb.Remote JavaDoc;
10 import javax.ejb.Stateless JavaDoc;
11 import javax.persistence.EntityManager;
12 import javax.persistence.EntityManagerFactory;
13 import javax.persistence.PersistenceContext;
14 import javax.persistence.PersistenceUnit;
15
16 /**
17  * Comment
18  *
19  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
20  * @version $Revision: 1.1.2.2 $
21  */

22 @Stateless JavaDoc
23 @Remote JavaDoc(Session1.class)
24 public class Session1Bean implements Session1
25 {
26    @PersistenceContext(unitName="manager1") EntityManager manager1;
27    @PersistenceContext(unitName="manager2") EntityManager manager2;
28    @PersistenceUnit(unitName="manager1") EntityManagerFactory factory1;
29    @PersistenceUnit(unitName="manager2") EntityManagerFactory factory2;
30
31    public int create1FromManager()
32    {
33       Entity1 one = new Entity1();
34       one.setString("oneManager");
35       manager1.persist(one);
36       return one.getId();
37    }
38    public int create1FromFactory()
39    {
40       Entity1 one = new Entity1();
41       one.setString("oneFactory");
42       EntityManager m = factory1.getEntityManager();
43       m.persist(one);
44       System.out.println(one.getId());
45       return one.getId();
46    }
47
48    public int create2FromManager()
49    {
50       Entity2 two = new Entity2();
51       two.setString("twoManager");
52       manager2.persist(two);
53       return two.getId();
54    }
55    public int create2FromFactory()
56    {
57       Entity2 two = new Entity2();
58       two.setString("twoFactory");
59       EntityManager m = factory2.createEntityManager();
60       m.persist(two);
61       return two.getId();
62    }
63 }
64
Popular Tags