01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb3.test.relationships;
23:
24: import javax.persistence.CascadeType;
25: import javax.persistence.Entity;
26: import javax.persistence.FetchType;
27: import javax.persistence.GeneratedValue;
28: import javax.persistence.GenerationType;
29: import javax.persistence.Id;
30: import javax.persistence.JoinColumn;
31: import javax.persistence.OneToMany;
32: import javax.persistence.Table;
33: import javax.persistence.Id;
34: import javax.persistence.ManyToOne;
35: import javax.persistence.ManyToOne;
36: import javax.persistence.CascadeType;
37: import javax.persistence.FetchType;
38: import javax.persistence.Entity;
39:
40: import java.io.Serializable;
41: import java.util.ArrayList;
42: import java.util.Collection;
43:
44: /**
45: * Comment
46: *
47: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
48: * @version $Revision: 57207 $
49: */
50: @Entity
51: @Table(name="PURCHASE_ORDER")
52: public class Order implements Serializable {
53: private long id;
54: private Collection<LineItem> items;
55: private Customer customer;
56:
57: @Id
58: @GeneratedValue(strategy=GenerationType.AUTO)
59: public long getId() {
60: return id;
61: }
62:
63: public void setId(long id) {
64: this .id = id;
65: }
66:
67: public void addPurchase(String product) {
68: if (items == null)
69: items = new ArrayList<LineItem>();
70: LineItem item = new LineItem();
71: item.setOrder(this );
72: item.setProduct(product);
73: items.add(item);
74: }
75:
76: @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
77: @JoinColumn(name="order_id")
78: public Collection<LineItem> getItems() {
79: return items;
80: }
81:
82: public void setItems(Collection<LineItem> items) {
83: this .items = items;
84: }
85:
86: @ManyToOne
87: @JoinColumn(name="CUST_ID")
88: public Customer getCustomer() {
89: return customer;
90: }
91:
92: public void setCustomer(Customer customer) {
93: this.customer = customer;
94: }
95:
96: }
|