我犯了个错误。sql语法有错误;查看与mysql服务器版本相对应的手册,在第1行的“order(id)”附近使用正确的语法,不知道为什么。有人能帮忙吗?以下是实体。订单可以有很多产品。产品可以关联到多个订单,而餐厅与产品有一对一的关系
@Entity
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToMany
@JoinTable(name = "order_product", joinColumns = @JoinColumn(name = "order_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "product_id", referencedColumnName = "id"))
private Set<Product> products = new HashSet<>();
}
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToOne
@JoinColumn(name = "restaurant_id", referencedColumnName = "id", insertable=false, updatable=false)
@JsonBackReference
private Restaurant restaurant;
private int restaurant_id;
private String name;
private String description;
private float price;
private float discount;
@ManyToMany(fetch = FetchType.EAGER)
@JsonIgnore
private Set<Order> orders = new HashSet<>();
}
@Entity
public class Restaurant {
@Id
@GeneratedValue
private int id;
@NotNull
private String name;
private String city;
private String address;
private String email;
private String phone;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "restaurant", cascade = CascadeType.ALL)
@JsonManagedReference
private List<Product> menu;
}
1条答案
按热度按时间mfpqipee1#
订单是有多个产品是好的和正确的。但从逻辑上讲,把订单和产品联系起来是不对的。所以我认为,只要从产品实体中删除以下行,就可以解决您的问题。