1 7 package org.jboss.tutorial.relationships.bean; 8 9 import java.util.HashSet ; 10 import java.util.Set ; 11 import javax.ejb.Remote ; 12 import javax.ejb.Stateless ; 13 import javax.persistence.EntityManager; 14 import javax.persistence.PersistenceContext; 15 16 22 @Stateless 23 @Remote (EntityTest.class) 24 public class EntityTestBean implements EntityTest 25 { 26 private @PersistenceContext EntityManager manager; 27 28 public void manyToManyCreate() throws Exception 29 { 30 31 Flight firstOne = new Flight(); 32 firstOne.setId(new Long (1)); 33 firstOne.setName("AF0101"); 34 manager.persist(firstOne); 35 Flight second = new Flight(); 36 second.setId(new Long (2)); 37 second.setName("US1"); 38 39 Set <Customer> customers1 = new HashSet <Customer>(); 40 Set <Customer> customers2 = new HashSet <Customer>(); 41 42 43 Customer bill = new Customer(); 44 bill.setName("Bill"); 45 Address address = new Address(); 46 address.setStreet("Clarendon Street"); 47 address.setCity("Boston"); 48 address.setState("MA"); 49 address.setZip("02116"); 50 bill.setAddress(address); 51 customers1.add(bill); 52 53 Customer monica = new Customer(); 54 monica.setName("Monica"); 55 address = new Address(); 56 address.setStreet("Beach Street"); 57 address.setCity("Somerville"); 58 address.setState("MA"); 59 address.setZip("02116"); 60 monica.setAddress(address); 61 customers1.add(monica); 62 63 Customer molly = new Customer(); 64 molly.setName("Molly"); 65 address = new Address(); 66 address.setStreet("Main Street"); 67 address.setCity("Billerica"); 68 address.setState("MA"); 69 address.setZip("02116"); 70 customers2.add(molly); 71 72 firstOne.setCustomers(customers1); 73 second.setCustomers(customers2); 74 75 manager.persist(second); 76 } 77 78 79 public Flight findFlightById(Long id) throws Exception 80 { 81 return manager.find(Flight.class, id); 82 } 83 84 } 85 | Popular Tags |