【发布时间】:2020-01-01 14:53:51
【问题描述】:
我有一个使用 JPA 的 spring boot 项目,所以我尝试使用它们的 Id 将两个表映射到第三个表: 例如我有一个优惠券类,我有一个客户类我想将客户 ID 和优惠券 ID 放入第三个表中。
我有优惠券:
@Entity
@Table(name = "coupons")
public class Coupon {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long coup_id;
private String title;
private String start;
private String end;
private int amount;
private String type;
private String message;
private double price;
private String image;
@ManyToMany(mappedBy = "coupons")
private List<Customer> customers;
我有客户:
@Entity
@Table(name="customers")
public class Customer {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int cust_id;
@Size(min=1,message="is required")
private String cust_name;
@Size(min = 1, message = "is required")
private String password;
@ManyToMany(cascade = { CascadeType.ALL })
@JoinTable(
name = "customer_coupon",
joinColumns = { @JoinColumn(name = "cust_id") },
inverseJoinColumns = { @JoinColumn(name = "coup_id") }
)
private List<Coupon> coupons;
我有连接表 customer_coupon:
这是我在启动项目时遇到的错误:
Caused by: org.hibernate.DuplicateMappingException: Table [coupons] contains physical column name [coup_id] referred to by multiple physical column names: [coupId], [coup_id]
我不知道它来自哪里,如果有人可以帮助我,我会很高兴!
【问题讨论】:
-
尝试重命名 private long coup_id; to private long coupId;
标签: java mysql hibernate jpa mysql-workbench