Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

@Entity
Expand All @@ -25,4 +27,7 @@ public class Inventory extends UriEntity {
private String location;

private int totalStock;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to implement this side of the relationship. Just need the ManyToOne side that is easier to persist into a relational database. The other side can be generated using a findByInventory method in the ProductRepository

@OneToMany(mappedBy = "inventory", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Product> products = new ArrayList<>();
}
7 changes: 3 additions & 4 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ public class Product extends UriEntity<Long>{
//TODO
// @OneToMany(cascade = CascadeType.ALL)
// private Set<Loyalty> loyalties;
//
//TODO
// @ManyToOne
// private Inventory inventory;

@ManyToOne
private Inventory inventory;


}