source: src/main/java/com/example/autopartz/model/Part.java

main
Last change on this file was 4d67d70, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 23 months ago

Final touches

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package com.example.autopartz.model;
2
3import lombok.Getter;
4import lombok.RequiredArgsConstructor;
5import lombok.Setter;
6import lombok.ToString;
7import org.hibernate.Hibernate;
8
9import javax.persistence.*;
10import java.util.List;
11import java.util.Objects;
12
13@Getter
14@Setter
15@ToString
16@RequiredArgsConstructor
17@Entity
18public class Part {
19 @Id
20 @GeneratedValue(strategy = GenerationType.IDENTITY)
21 @Column(name = "ID_part")
22 Integer id;
23 @Column(name = "part_name")
24 String name;
25 @Column(name = "part_description")
26 String description;
27 @ManyToOne
28 @JoinColumn(name = "id_part_manufacturer")
29 PartManufacturer manufacturer;
30 @ManyToMany
31 @JoinTable(name = "part_is_from_category", joinColumns =
32 @JoinColumn(name = "id_part"),
33 inverseJoinColumns = @JoinColumn(name = "id_category"))
34 @ToString.Exclude
35 List<Category> categoryList;
36 @ManyToMany
37 @JoinTable(name = "part_is_in_stock_in_warehouse", joinColumns =
38 @JoinColumn(name = "id_part"),
39 inverseJoinColumns = @JoinColumn(name = "id_warehouse"))
40 @ToString.Exclude
41 List<Warehouse> warehouseList;
42 @ManyToMany
43 @JoinTable(name = "part_is_appropriate_for_car", joinColumns =
44 @JoinColumn(name = "id_part"),
45 inverseJoinColumns = @JoinColumn(name = "id_car"))
46 @ToString.Exclude
47 List<Car> carList;
48
49 public Part(String name, String description, PartManufacturer manufacturer, List<Category> categoryList, List<Warehouse> warehouseList, List<Car> carList) {
50 this.name = name;
51 this.description = description;
52 this.manufacturer = manufacturer;
53 this.categoryList = categoryList;
54 this.warehouseList = warehouseList;
55 this.carList = carList;
56 }
57
58 @Override
59 public boolean equals(Object o) {
60 if (this == o) return true;
61 if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
62 Part part = (Part) o;
63 return id != null && Objects.equals(id, part.id);
64 }
65
66 @Override
67 public int hashCode() {
68 return getClass().hashCode();
69 }
70}
Note: See TracBrowser for help on using the repository browser.