1 7 package org.jboss.tutorial.packaging.bean; 8 9 import javax.ejb.Remote ; 10 import javax.ejb.Stateless ; 11 import javax.persistence.EntityManager; 12 import javax.persistence.EntityManagerFactory; 13 import javax.persistence.PersistenceContext; 14 import javax.persistence.PersistenceUnit; 15 16 22 @Stateless 23 @Remote (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 |