-
Notifications
You must be signed in to change notification settings - Fork 508
/
Copy pathBeer.java
53 lines (43 loc) · 1.27 KB
/
Beer.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
package guru.springframework.spring6restmvc.entities;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import jakarta.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Beer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
private String name;
private String style;
private String upc;
private Integer quantityOnHand;
private BigDecimal price;
@CreationTimestamp
private LocalDateTime createdDate;
@UpdateTimestamp
private LocalDateTime lastModifiedDate;
@ManyToMany
@JoinTable(name = "beer_category",
joinColumns = @JoinColumn(name = "beer_id"),
inverseJoinColumns = @JoinColumn(name = "category_id"))
private Set<Category> categories = new HashSet<>();
public void addCategory(Category category){
this.categories.add(category);
category.getBeers().add(this);
}
public void removeCategory(Category category){
this.categories.remove(category);
category.getBeers().remove(this);
}
}