1 22 package org.jboss.ejb3.test.standalone.flushmodenever; 23 24 import javax.ejb.Remote ; 25 import javax.ejb.Stateless ; 26 import javax.ejb.EJB ; 27 import javax.persistence.EntityManager; 28 import javax.persistence.EntityManagerFactory; 29 import javax.persistence.PersistenceContext; 30 import javax.persistence.PersistenceUnit; 31 import org.hibernate.SessionFactory; 32 import org.hibernate.Session; 33 34 40 @Stateless 41 @Remote (Session1.class) 42 public class Session1Bean implements Session1 43 { 44 @PersistenceContext(unitName="manager1") Session manager1; 45 @PersistenceContext(unitName="../flushmodenever-session2.jar#manager2") EntityManager manager2; 46 @PersistenceUnit(unitName="manager1") SessionFactory factory1; 47 @PersistenceUnit(unitName="../flushmodenever-session2.jar#manager2") EntityManagerFactory factory2; 48 @EJB Session2 session2; 49 50 public int create1FromManager() 51 { 52 Entity1 one = new Entity1(); 53 one.setString("oneManager"); 54 manager1.save(one); 55 return one.getId(); 56 } 57 public int create1FromFactory() 58 { 59 Entity1 one = new Entity1(); 60 Session m = factory1.openSession(); 61 m.save(one); 62 return one.getId(); 64 } 65 66 public int create2FromManager() 67 { 68 Entity2 two = new Entity2(); 69 two.setString("twoManager"); 70 manager2.persist(two); 71 return two.getId(); 72 } 73 public int create2FromFactory() 74 { 75 Entity2 two = new Entity2(); 76 EntityManager m = factory2.createEntityManager(); 77 m.persist(two); 78 return two.getId(); 80 } 81 82 public void doUtil(Util ux) 83 { 84 Util u = new Util(); 85 u.setId(1); 86 u.setName("one"); 87 manager1.persist(u); 88 89 u = new Util(); 90 u.setId(2); 91 u.setName("two"); 92 manager2.persist(u); 93 } 94 95 } 96 | Popular Tags |