1 22 package org.jboss.ejb3.test.regression; 23 24 import java.util.List ; 25 import javax.ejb.Remote ; 26 import javax.ejb.Stateless ; 27 import javax.persistence.EntityManager; 28 import javax.persistence.PersistenceContext; 29 import javax.persistence.Query; 30 import javax.persistence.PersistenceContext; 31 32 38 @Stateless 39 @Remote (InheritanceSession.class) 40 public class InheritanceSessionBean implements InheritanceSession 41 { 42 @PersistenceContext 43 private EntityManager em; 44 45 public long createBranch() 46 { 47 FootballTeam branch = new FootballTeam(); 48 branch.setCity("Foxboro"); 49 branch.setCountry("USA"); 50 branch.setName("NE Pats"); 51 branch.setPhone("617-666-6666"); 52 branch.setEmail("boston@boston.com"); 53 branch.setSuperbowlsWon(2); 54 55 Employee employee = new Employee(); 56 employee.setName("Tom Brady"); 57 employee.setPhone("617-666-6666"); 58 employee.setEmail("boston@boston.com"); 59 employee.setFirst("Tom"); 60 employee.setLast("Brady"); 61 employee.setCell("617-666-6666"); 62 branch.addEmployee(employee); 63 64 Manager manager = new Manager(); 65 manager.setName("Bill Belicheck"); 66 manager.setPhone("617-666-6666"); 67 manager.setEmail("boston@boston.com"); 68 manager.setFirst("Bill"); 69 manager.setLast("Belicheck"); 70 manager.setCell("617-666-6666"); 71 manager.setTitle("Head Coach"); 72 branch.addEmployee(manager); 73 em.persist(branch); 74 return branch.getId(); 75 } 76 77 public Branch getBranch(long id) 78 { 79 return em.find(Branch.class, id); 80 } 81 82 public List getContacts() 83 { 84 Query query = em.createQuery("from Contact"); 85 return query.getResultList(); 86 } 87 } 88 | Popular Tags |