KickJava   Java API By Example, From Geeks To Geeks.

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


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(Session2.class)
24 public class Session2Bean implements Session2
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 Entity1 find1FromManager(int id)
32    {
33       return manager1.find(Entity1.class, id);
34    }
35    public Entity1 find1FromFactory(int id)
36    {
37       EntityManager m = factory1.getEntityManager();
38       Entity1 one = m.find(Entity1.class, id);
39       return one;
40    }
41    public Entity2 find2FromManager(int id)
42    {
43       return manager2.find(Entity2.class, id);
44    }
45    public Entity2 find2FromFactory(int id)
46    {
47       EntityManager m = factory2.createEntityManager();
48       Entity2 two = m.find(Entity2.class, id);
49       m.close();
50       return two;
51    }
52
53 }
54
Popular Tags