File tree 2 files changed +19
-0
lines changed
src/main/java/com/manir/springbootecommercerestapi/resource
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 5
5
import lombok .NoArgsConstructor ;
6
6
7
7
import javax .persistence .*;
8
+ import java .util .HashSet ;
9
+ import java .util .List ;
10
+ import java .util .Set ;
8
11
9
12
@ AllArgsConstructor
10
13
@ NoArgsConstructor
@@ -24,4 +27,15 @@ public class Category {
24
27
private String description ;
25
28
@ Column (name = "status" )
26
29
private String status ;
30
+
31
+ //relation between parent and child categories
32
+ @ ManyToOne
33
+ @ JoinColumn (name = "parent_id" )
34
+ private Category parent ;
35
+ @ OneToMany (mappedBy = "parent" )
36
+ private Set <Category > children = new HashSet <>();
37
+
38
+ //relation between category and product
39
+ @ OneToMany (mappedBy = "category" , cascade = CascadeType .ALL , orphanRemoval = true )
40
+ private Set <Product > products = new HashSet <>();
27
41
}
Original file line number Diff line number Diff line change @@ -29,4 +29,9 @@ public class Product {
29
29
private Integer quantity ;
30
30
@ Column (name = "status" )
31
31
private String status ;
32
+
33
+ //relation between category and product
34
+ @ ManyToOne (fetch = FetchType .LAZY )
35
+ @ JoinColumn (name = "category_id" )
36
+ Category category ;
32
37
}
You can’t perform that action at this time.
0 commit comments