Skip to content
Snippets Groups Projects
Commit 4913be0c authored by Stian Lyng's avatar Stian Lyng
Browse files

add many to many relationships

parent 0d5cc4ab
Branches
No related tags found
No related merge requests found
package ntnu.idatt2016.v233.SmartMat.entity; package ntnu.idatt2016.v233.SmartMat.entity;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import ntnu.idatt2016.v233.SmartMat.entity.product.Product;
/** /**
* Recipe is an entity class representing a recipe in the system. * Recipe is an entity class representing a recipe in the system.
* *
* @author Anders * @author Anders & Stian
* @version 1.0.001 * @version 1.0.001
* @since 19.04.2023 * @since 19.04.2023
* *
...@@ -31,4 +36,12 @@ public class Recipe { ...@@ -31,4 +36,12 @@ public class Recipe {
@Column(name = "recipe_description") @Column(name = "recipe_description")
String description; String description;
@ManyToMany
@JoinTable(name = "recipe_product",
joinColumns = @JoinColumn(name = "recipe_id"),
inverseJoinColumns = @JoinColumn(name = "ean"))
@JsonIgnoreProperties({"recipes"})
List<Product> products;
} }
...@@ -8,6 +8,7 @@ import lombok.Builder; ...@@ -8,6 +8,7 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import ntnu.idatt2016.v233.SmartMat.entity.Fridge; import ntnu.idatt2016.v233.SmartMat.entity.Fridge;
import ntnu.idatt2016.v233.SmartMat.entity.Recipe;
import java.util.List; import java.util.List;
...@@ -64,4 +65,9 @@ public class Product{ ...@@ -64,4 +65,9 @@ public class Product{
@ManyToMany(mappedBy = "products") @ManyToMany(mappedBy = "products")
@JsonIgnoreProperties({"products"}) @JsonIgnoreProperties({"products"})
List<Fridge> fridges; List<Fridge> fridges;
@ManyToMany(mappedBy = "products")
@JsonIgnoreProperties({"products"})
List<Recipe> recipes;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment