-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathProduct.java
115 lines (90 loc) · 2.52 KB
/
Product.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package me.anant.PMS.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* Domain model describing Product and its attributes.
*/
@Entity
public class Product {
@Id
@GeneratedValue
long productId;
@NotBlank(message="Product name can not be empty")
@Size(min = 3, message="Product name should be of minimum 3 character")
String productName;
@NotNull
@Min(value=0, message="Product price can not be negative value.")
float productPrice;
@NotNull
@Min(value=0, message="Product quantity can not be negative")
@Max(value=50, message="Product quantity can be maximum 50.")
int productQty;
@JsonIgnore
@OneToMany(mappedBy = "product", cascade = CascadeType.ALL)
Set<OrderProduct> orderProduct;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
ProductCategory category;
public Product() {
// TODO Auto-generated constructor stub
}
public Product(long productId) {
super();
this.productId = productId;
}
public Product(String productName, float productPrice, int productQty, ProductCategory category) {
super();
this.productName = productName;
this.productPrice = productPrice;
this.productQty = productQty;
this.category = category;
}
public long getProductId() {
return productId;
}
public void setProductId(long productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public float getProductPrice() {
return productPrice;
}
public void setProductPrice(float productPrice) {
this.productPrice = productPrice;
}
public int getProductQty() {
return productQty;
}
public void setProductQty(int productQty) {
this.productQty = productQty;
}
public Set<OrderProduct> getOrderProduct() {
return orderProduct;
}
public void setOrderProduct(Set<OrderProduct> orderProduct) {
this.orderProduct = orderProduct;
}
public ProductCategory getCategory() {
return category;
}
public void setCategory(ProductCategory category) {
this.category = category;
}
}