KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > relationships > bean > EntityTestBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.relationships.bean;
8
9 import java.util.HashSet JavaDoc;
10 import java.util.Set JavaDoc;
11 import javax.ejb.Remote JavaDoc;
12 import javax.ejb.Stateless JavaDoc;
13 import javax.persistence.EntityManager;
14 import javax.persistence.PersistenceContext;
15
16 /**
17  * Comment
18  *
19  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
20  * @version $Revision: 1.5.2.3 $
21  */

22 @Stateless JavaDoc
23 @Remote JavaDoc(EntityTest.class)
24 public class EntityTestBean implements EntityTest
25 {
26    private @PersistenceContext EntityManager manager;
27
28    public void manyToManyCreate() throws Exception JavaDoc
29    {
30
31       Flight firstOne = new Flight();
32       firstOne.setId(new Long JavaDoc(1));
33       firstOne.setName("AF0101");
34       manager.persist(firstOne);
35       Flight second = new Flight();
36       second.setId(new Long JavaDoc(2));
37       second.setName("US1");
38
39       Set JavaDoc<Customer> customers1 = new HashSet JavaDoc<Customer>();
40       Set JavaDoc<Customer> customers2 = new HashSet JavaDoc<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 JavaDoc id) throws Exception JavaDoc
80    {
81       return manager.find(Flight.class, id);
82    }
83
84 }
85
Popular Tags