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