Skip to content

Introduction mockmvc #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Many To Many JPA Relationships
nraigosam committed May 12, 2023
commit cd3b313840d1bb8f9a83240a9d8e01d386d0fc80
40 changes: 40 additions & 0 deletions src/main/java/guru/springframework/domain/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package guru.springframework.domain;

import javax.persistence.*;
import java.util.Set;

@Entity
public class Category {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String description;

@ManyToMany(mappedBy = "categories")
private Set<Recipe> recipes;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Set<Recipe> getRecipes() {
return recipes;
}

public void setRecipes(Set<Recipe> recipes) {
this.recipes = recipes;
}
}
14 changes: 14 additions & 0 deletions src/main/java/guru/springframework/domain/Recipe.java
Original file line number Diff line number Diff line change
@@ -35,6 +35,12 @@ public class Recipe {
@OneToOne(cascade = CascadeType.ALL)
private Notes notes;

@ManyToMany
@JoinTable(name = "recipe_category ",
joinColumns = @JoinColumn(name = "recipe_id"),
inverseJoinColumns = @JoinColumn(name = "category_id"))
private Set<Category> categories;

public Long getId() {
return id;
}
@@ -130,4 +136,12 @@ public Notes getNotes() {
public void setNotes(Notes notes) {
this.notes = notes;
}

public Set<Category> getCategories() {
return categories;
}

public void setCategories(Set<Category> categories) {
this.categories = categories;
}
}