1 7 package org.jboss.tutorial.composite.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 import javax.persistence.PersistenceContext; 16 17 23 @Stateless 24 @Remote (EntityTest.class) 25 public class EntityTestBean implements EntityTest 26 { 27 private @PersistenceContext EntityManager manager; 28 private static long genid = 0; 29 30 public void manyToManyCreate() throws Exception 31 { 32 33 Flight firstOne = new Flight(); 34 firstOne.setId(new Long (1)); 35 firstOne.setName("AF0101"); 36 manager.persist(firstOne); 37 Flight second = new Flight(); 38 second.setId(new Long (2)); 39 second.setName("US1"); 40 41 Set <Customer> customers1 = new HashSet <Customer>(); 42 Set <Customer> customers2 = new HashSet <Customer>(); 43 44 45 Customer bill = new Customer(); 46 CustomerPK pk = new CustomerPK(genid++, "Bill"); 47 bill.setPk(pk); 48 customers1.add(bill); 49 50 Customer monica = new Customer(); 51 CustomerPK moPK = new CustomerPK(genid++, "Monica"); 52 monica.setPk(moPK); 53 customers1.add(monica); 54 55 Customer molly = new Customer(); 56 CustomerPK mollyPK = new CustomerPK(genid++, "Molly"); 57 molly.setPk(mollyPK); 58 customers2.add(molly); 59 60 firstOne.setCustomers(customers1); 61 second.setCustomers(customers2); 62 63 manager.persist(second); 64 } 65 66 67 public Flight findFlightById(Long id) throws Exception 68 { 69 return manager.find(Flight.class, id); 70 } 71 72 } 73 | Popular Tags |