From d1d78f21b24fb0da43b6360466d189491a477496 Mon Sep 17 00:00:00 2001 From: mrfoxygmfr Date: Mon, 24 Mar 2025 12:20:54 +0300 Subject: chore(db/models): enable autogeneration for timestamp fields --- .../warehouse_accounting/db/models/Operation.java | 20 +++++----- .../db/models/OperationProduct.java | 33 ++++++++++++++++ .../db/models/OperationProducts.java | 33 ---------------- .../db/models/ProductSlot.java | 46 ++++++++++++++++++++++ .../db/models/ProductSlots.java | 45 --------------------- 5 files changed, 90 insertions(+), 87 deletions(-) create mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java delete mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java create mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java delete mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java (limited to 'src') 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 products; + @OneToMany(mappedBy = "operation", cascade=CascadeType.ALL, orphanRemoval = true) + @ToString.Exclude + private Set products; } diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java new file mode 100644 index 0000000..97881bd --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProduct.java @@ -0,0 +1,33 @@ +package ru.mrfoxygmfr.warehouse_accounting.db.models; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name = "operation_products") +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +public class OperationProduct { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, name = "id") + private int id; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "operation_id", referencedColumnName = "id") + @NonNull + private Operation operation; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "product_id", referencedColumnName = "id") + @NonNull + private Product product; + + @Column(nullable = false, name = "amount") + @NonNull + private long amount; +} diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java deleted file mode 100644 index 2a842a2..0000000 --- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/OperationProducts.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.mrfoxygmfr.warehouse_accounting.db.models; - -import jakarta.persistence.*; -import lombok.*; - -@Entity -@Table(name = "operation_products") -@Getter -@Setter -@ToString -@NoArgsConstructor -@RequiredArgsConstructor -@AllArgsConstructor -public class OperationProducts { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(nullable = false, name = "id") - private int id; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "operation_id", referencedColumnName = "id") - @NonNull - private Operation operation; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "product_id", referencedColumnName = "id") - @NonNull - private Product product; - - @Column(nullable = false, name = "amount") - @NonNull - private long amount; -} diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java new file mode 100644 index 0000000..c394d67 --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlot.java @@ -0,0 +1,46 @@ +package ru.mrfoxygmfr.warehouse_accounting.db.models; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.CreationTimestamp; + +import java.sql.Timestamp; + +@Entity +@Table(name = "product_slots") +@Getter +@Setter +@ToString +@NoArgsConstructor +@RequiredArgsConstructor +@AllArgsConstructor +public class ProductSlot { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, name = "id") + private int id; + + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "product_id", referencedColumnName = "id") + @NonNull + private Product product; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "slot_id", referencedColumnName = "id") + @NonNull + private StorageSlot slot; + + @Column(nullable = false, name = "amount") + @NonNull + private long amount; + + @Column(nullable = false, name = "status") + @Enumerated(EnumType.STRING) + @NonNull + private ProductStorageStatus status; + + @Column(nullable = false, name = "placement_time", updatable = false) + @CreationTimestamp + private Timestamp placementTime; +} diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java deleted file mode 100644 index 640ef6f..0000000 --- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/ProductSlots.java +++ /dev/null @@ -1,45 +0,0 @@ -package ru.mrfoxygmfr.warehouse_accounting.db.models; - -import jakarta.persistence.*; -import lombok.*; - -import java.sql.Timestamp; - -@Entity -@Table(name = "product_slots") -@Getter -@Setter -@ToString -@NoArgsConstructor -@RequiredArgsConstructor -@AllArgsConstructor -public class ProductSlots { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(nullable = false, name = "id") - private int id; - - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "product_id", referencedColumnName = "id") - @NonNull - private Product product; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "slot_id", referencedColumnName = "id") - @NonNull - private StorageSlot slot; - - @Column(nullable = false, name = "amount") - @NonNull - private long amount; - - @Column(nullable = false, name = "status") - @Enumerated(EnumType.STRING) - @NonNull - private ProductStorageStatus status; - - @Column(nullable = false, name = "placement_time") - @NonNull - private Timestamp placementTime; -} -- cgit mrf-deployment