DataJPA/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java
2020-05-18 14:51:58 +07:00

104 lines
2.4 KiB
Java

package com.chantha.jdbc.jpa.model;
import com.chantha.jdbc.utils.CustomDateDeserializer;
import com.chantha.jdbc.utils.CustomDateSerializer;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Entity
@Table(name = "tbOrder")
public class Order implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long orderId;
@JsonSerialize(using = CustomDateSerializer.class)
@JsonDeserialize(using = CustomDateDeserializer.class)
private Date orderDate;
private double amount;
@ManyToOne(fetch = FetchType.LAZY)
@JsonBackReference
@JoinColumn(name = "cusId",nullable = false,referencedColumnName = "id")
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
@JsonBackReference
@JoinColumn(name = "sid",nullable = false,referencedColumnName = "id")
private Staff staff;
@OneToMany(mappedBy = "order")
private List<OrderDetail> orderDetails;
public Long getOrderId() {
return orderId;
}
public Staff getStaff() {
return staff;
}
public void setStaff(Staff staff) {
this.staff = staff;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
@JsonManagedReference
public List<OrderDetail> getOrderDetails() {
return orderDetails;
}
public void setOrderDetails(List<OrderDetail> orderDetails) {
this.orderDetails = orderDetails;
}
public Order() {
}
public Order(Long orderId,Date orderDate,double amount,Customer customer,List<OrderDetail> orderDetails,Staff staff) {
this.orderId=orderId;
this.orderDate=orderDate;
this.amount=amount;
this.orderDetails=orderDetails;
this.staff=staff;
}
}