// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="myorder")
public class OrderJPA {
    private int id;
    private String customer;
    private List<OrderLineJPA> lines;
    public OrderJPA() {
        this(0, "", new ArrayList<OrderLineJPA>());
    }
    public OrderJPA(int id, String customer) {
        this(id, customer, new ArrayList<OrderLineJPA>());
    }
    public OrderJPA(int id, String customer, List<OrderLineJPA> lines) {
        this.id = id;
        this.customer = customer;
        this.lines = lines;
    }
    @Id
    @Column(name="id")
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name="customer")
    public String getCustomer() {
        return customer;
    }
    public void setCustomer(String customer) {
        this.customer = customer;
    }
    @OneToMany(mappedBy = "orderId", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    public List<OrderLineJPA> getLines() {
        return lines;
    }
    public void setLines(List<OrderLineJPA> lines) {
        this.lines = lines;
    }
}
