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 (Session1.class) 24 public class Session1Bean implements Session1 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 int create1FromManager() 32 { 33 Entity1 one = new Entity1(); 34 one.setString("oneManager"); 35 manager1.persist(one); 36 return one.getId(); 37 } 38 public int create1FromFactory() 39 { 40 Entity1 one = new Entity1(); 41 one.setString("oneFactory"); 42 EntityManager m = factory1.getEntityManager(); 43 m.persist(one); 44 System.out.println(one.getId()); 45 return one.getId(); 46 } 47 48 public int create2FromManager() 49 { 50 Entity2 two = new Entity2(); 51 two.setString("twoManager"); 52 manager2.persist(two); 53 return two.getId(); 54 } 55 public int create2FromFactory() 56 { 57 Entity2 two = new Entity2(); 58 two.setString("twoFactory"); 59 EntityManager m = factory2.createEntityManager(); 60 m.persist(two); 61 return two.getId(); 62 } 63 } 64 | Popular Tags |