gpt4 book ai didi

MySQLSyntaxErrorException : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

转载 作者:行者123 更新时间:2023-11-29 16:49:16 25 4
gpt4 key购买 nike

我收到错误。您的 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;
}

最佳答案

订单有多个产品,这些产品也都正常且正确。但从逻辑上讲,将订单与产品联系起来是不对的。所以我认为如果只从 Product 实体中删除以下行就可以解决您的问题。

@ManyToMany
@JoinTable(name = "order_product", joinColumns = @JoinColumn(name = "product_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name ="order_id", referencedColumnName = "order_id"))
private Set<Order> order;

关于MySQLSyntaxErrorException : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52903778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com