1 22 package org.jboss.ejb3.test.factory; 23 24 import javax.ejb.Remote ; 25 import javax.ejb.SessionContext ; 26 import javax.ejb.Stateless ; 27 import javax.ejb.EJB ; 28 import javax.persistence.EntityManager; 29 import javax.persistence.EntityManagerFactory; 30 import javax.persistence.PersistenceContext; 31 import javax.persistence.PersistenceUnit; 32 import javax.annotation.Resource; 33 34 import org.hibernate.SessionFactory; 35 import org.hibernate.Session; 36 37 43 @Stateless 44 @Remote (Session1.class) 45 @PersistenceContext(name="encManager1") 46 public class Session1Bean implements Session1 47 { 48 @PersistenceContext(unitName="manager1") Session manager1; 49 @PersistenceContext(unitName="../session2.jar#manager2") EntityManager manager2; 50 @PersistenceUnit(unitName="manager1") SessionFactory factory1; 51 @PersistenceUnit(unitName="../session2.jar#manager2") EntityManagerFactory factory2; 52 @EJB Session2 session2; 53 54 @Resource SessionContext ctx; 55 56 public int create1FromManager() 57 { 58 EntityManager enc = (EntityManager)ctx.lookup("encManager1"); 59 Entity1 first = new Entity1(); 60 first.setString("blah"); 61 enc.persist(first); 62 63 Entity1 one = new Entity1(); 64 one.setString("oneManager"); 65 manager1.save(one); 66 return one.getId(); 67 } 68 public int create1FromFactory() 69 { 70 Entity1 one = new Entity1(); 71 Session m = factory1.openSession(); 72 m.save(one); 73 return one.getId(); 75 } 76 77 public int create2FromManager() 78 { 79 Entity2 two = new Entity2(); 80 two.setString("twoManager"); 81 manager2.persist(two); 82 return two.getId(); 83 } 84 public int create2FromFactory() 85 { 86 Entity2 two = new Entity2(); 87 EntityManager m = factory2.createEntityManager(); 88 m.persist(two); 89 return two.getId(); 91 } 92 93 public void doUtil(Util ux) 94 { 95 Util u = new Util(); 96 u.setId(1); 97 u.setName("one"); 98 manager1.persist(u); 99 100 u = new Util(); 101 u.setId(2); 102 u.setName("two"); 103 manager2.persist(u); 104 } 105 106 } 107 | Popular Tags |