-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJarExpenseCategory.java
52 lines (41 loc) · 1.78 KB
/
JarExpenseCategory.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
package io.myfinbox.spendingplan.domain;
import jakarta.persistence.*;
import lombok.*;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import static io.myfinbox.shared.Guards.*;
import static jakarta.persistence.CascadeType.ALL;
import static jakarta.persistence.GenerationType.SEQUENCE;
import static lombok.AccessLevel.PACKAGE;
@Entity
@Getter
@ToString(exclude = {"jar", "expenseRecords"})
@Table(name = "spending_jar_expense_category")
@EqualsAndHashCode(of = {"id", "jar", "categoryId"})
@NoArgsConstructor(access = PACKAGE, force = true)
public class JarExpenseCategory {
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "sjec_seq_id")
@SequenceGenerator(name = "sjec_seq_id", sequenceName = "sjec_seq_id", allocationSize = 1)
// https://vladmihalcea.com/migrate-hilo-hibernate-pooled/
private Long id;
private final Instant creationTimestamp;
@Embedded
@AttributeOverride(name = "id", column = @Column(name = "category_id"))
private final CategoryIdentifier categoryId;
@Column(name = "category_name", nullable = false)
private String categoryName;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "jar_id", referencedColumnName = "id", nullable = false)
private final Jar jar;
@OneToMany(mappedBy = "jarExpenseCategory", cascade = ALL, orphanRemoval = true)
private List<ExpenseRecord> expenseRecords = new ArrayList<>();
@Builder
public JarExpenseCategory(Jar jar, CategoryIdentifier categoryId, String categoryName) {
this.jar = notNull(jar, "jar cannot be null.");
this.categoryId = notNull(categoryId, "categoryId cannot be null.");
this.categoryName = notBlank(categoryName, "categoryName cannot be null.");
this.creationTimestamp = Instant.now();
}
}