ranyeli
9/3/2017 - 5:31 AM

CustomerOrder model sample on JAVA + JPA

CustomerOrder model sample on JAVA + JPA

package com.project.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;


@Entity
@Table(name="cust_order")
public class CustomerOrder {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private long id;
		
	@ManyToOne(optional=false)
	private Customer customer;
	
	@OneToOne(optional=false, mappedBy="order", targetEntity=Invoice.class, cascade=CascadeType.ALL)
	private Invoice invoice;
	
	@JsonManagedReference
	@OneToMany(mappedBy="order", cascade={CascadeType.PERSIST, CascadeType.MERGE})
	private List<OrderItem> orderItem = new ArrayList<OrderItem>();

	public List<OrderItem> getOrderItem() {
		return orderItem;
	}

	public void setOrderItem(List<OrderItem> orderItem) {
		this.orderItem = orderItem;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public long getId() {
		return id;
	}

}