aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-24 12:20:54 +0300
committermrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-24 12:20:54 +0300
commitd1d78f21b24fb0da43b6360466d189491a477496 (patch)
tree802a16279943dd5c1e8d2e68eb7c80c06b2e793d
parent193277eec8ba949f37808544953765875c9a0f44 (diff)
chore(db/models): enable autogeneration for timestamp fields
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java20
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java (renamed from src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java)2
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java (renamed from src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java)7
3 files changed, 16 insertions, 13 deletions
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java
index d1eb400..22116f8 100644
--- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java
@@ -2,6 +2,8 @@ package ru.mrfoxygmfr.warehouse_accounting.db.models;
import jakarta.persistence.*;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.UpdateTimestamp;
import java.sql.Timestamp;
import java.util.Set;
@@ -20,7 +22,7 @@ public class Operation {
@Column(nullable = false, name = "id")
private int id;
- @ManyToOne(fetch = FetchType.EAGER)
+ @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "partner_id", referencedColumnName = "id")
@NonNull
private Partner partner;
@@ -35,16 +37,15 @@ public class Operation {
@NonNull
private OperationStatus status;
- @Column(nullable = false, name = "date_created")
- @NonNull
+ @Column(nullable = false, name = "date_created", updatable = false)
+ @CreationTimestamp
private Timestamp dateCreated;
@Column(nullable = false, name = "date_modified")
- @NonNull
+ @UpdateTimestamp
private Timestamp dateModified;
- @Column(nullable = false, name = "date_finished")
- @NonNull
+ @Column(nullable = true, name = "date_finished")
private Timestamp dateFinished;
@@ -52,11 +53,12 @@ public class Operation {
@NonNull
private String address;
- @ManyToOne(fetch = FetchType.EAGER)
+ @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "responsible_id", referencedColumnName = "id")
@NonNull
private PartnerContact responsible;
- @OneToMany(mappedBy = "operation")
- private Set<OperationProducts> products;
+ @OneToMany(mappedBy = "operation", cascade=CascadeType.ALL, orphanRemoval = true)
+ @ToString.Exclude
+ private Set<OperationProduct> products;
}
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java
index 2a842a2..97881bd 100644
--- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java
@@ -11,7 +11,7 @@ import lombok.*;
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
-public class OperationProducts {
+public class OperationProduct {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, name = "id")
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java
index 640ef6f..c394d67 100644
--- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java
@@ -2,6 +2,7 @@ package ru.mrfoxygmfr.warehouse_accounting.db.models;
import jakarta.persistence.*;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
import java.sql.Timestamp;
@@ -13,7 +14,7 @@ import java.sql.Timestamp;
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
-public class ProductSlots {
+public class ProductSlot {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, name = "id")
@@ -39,7 +40,7 @@ public class ProductSlots {
@NonNull
private ProductStorageStatus status;
- @Column(nullable = false, name = "placement_time")
- @NonNull
+ @Column(nullable = false, name = "placement_time", updatable = false)
+ @CreationTimestamp
private Timestamp placementTime;
}