【发布时间】:2019-03-25 00:27:56
【问题描述】:
我收到一个错误。 您的 SQL 语法有误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“订单(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;
}
【问题讨论】:
标签: mysql spring spring-data-jpa hibernate-mapping