KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > composite > 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.composite.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 import javax.persistence.PersistenceContext;
16
17 /**
18  * Comment
19  *
20  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
21  * @version $Revision: 1.5.2.4 $
22  */

23 @Stateless JavaDoc
24 @Remote JavaDoc(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 JavaDoc
31    {
32
33       Flight firstOne = new Flight();
34       firstOne.setId(new Long JavaDoc(1));
35       firstOne.setName("AF0101");
36       manager.persist(firstOne);
37       Flight second = new Flight();
38       second.setId(new Long JavaDoc(2));
39       second.setName("US1");
40
41       Set JavaDoc<Customer> customers1 = new HashSet JavaDoc<Customer>();
42       Set JavaDoc<Customer> customers2 = new HashSet JavaDoc<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 JavaDoc id) throws Exception JavaDoc
68    {
69       return manager.find(Flight.class, id);
70    }
71
72 }
73
Popular Tags