I have a requirement where User will be able to search for a restaurant based on location and checks the menu of the restaurant. The menu contains various items like soups, starters, main course etc. The admin user should be able to new restaurant, the menu and the items and their prices.
Now in java, I have this relationship, I am adding required code only for clarity:
Restaurant.java
@Entity
public class Restaurant {
@Id
private Long id;
private String name;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "restaurant_menu")
private Menu menu;
}
Menu.java
@Entity
public class Menu {
@Id
private Long id;
private String name;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "menu_soups", joinColumns = { @JoinColumn(name = "menu_id") }, inverseJoinColumns = { @JoinColumn(name = "soup_id") })
private Set<Soup> soups = new HashSet<Soup>();
}
Soup.java
@Entity
public class Soup {
@Id
private Long id;
private String name;
}
Now I am confused like where should I keep the price details. Since menu and soup have many-to-many relationship, I should maintain a separate table. But how can I do that in hibernate.