So I have three classes (In my database I have over a dozen, but those three are problematic), and there several things I want to do with them:
WarmProduct inhert from Product
WarmProduct is made from several Products with Enum "SKŁADNIK"
Enums ZIMNY or CIEPŁY, SNACK are types of products selled in automats (each automat also have Enum ZIMNY, CIEPŁY or SNACK, but they are others from those in Product)
In automats with SNACK or ZIMNY I just keep products and their quantity.
In automat CIEPŁY I need to create WarmProduct from products with Enum "SKŁADNIK", then keep info about quantity of inserter SKŁADNIK and selled WarmProducts.
Also I need to combine info from all automats.
@Entity
public class Product {
public enum types {
ZIMNY, CIEPŁY, SNACK, SKŁADNIK;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(updatable = false, unique = true)
@NotBlank(message = "Name is required")
private String name;
@NotBlank(message = "Type is required")
@Column(updatable = false)
private Enum<types> type;
@NotNull(message = "deleted is required")
private Integer deleted = 0;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "warmproduct_id", referencedColumnName = "id")
private WarmProduct warmProduct;
}
@Entity
public class WarmProduct extends Product {
@OneToMany
@JoinColumn(name = "product_id", referencedColumnName = "id")
private Set<Product> product;
}
@Entity
public class Automat {
public enum types {
ZIMNY,CIEPLY,SNACK;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank(message = "Nazwa jest wymagana")
private String name;
}
My problem is: how to project relations between Product, WarmProduct and Automat to have as clear databse construction as possible?