1 | package com.example.autopartz.model;
|
---|
2 |
|
---|
3 | import lombok.Getter;
|
---|
4 | import lombok.RequiredArgsConstructor;
|
---|
5 | import lombok.Setter;
|
---|
6 | import lombok.ToString;
|
---|
7 | import org.hibernate.Hibernate;
|
---|
8 |
|
---|
9 | import javax.persistence.*;
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Objects;
|
---|
12 |
|
---|
13 | @Getter
|
---|
14 | @Setter
|
---|
15 | @ToString
|
---|
16 | @RequiredArgsConstructor
|
---|
17 | @Entity
|
---|
18 | public 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 | }
|
---|