使用 question_id 字段生成表 question_list_sent - 此字段包含唯一索引。如何将此字段注释为正常而非唯一。
@Entity
@Table(name = "question_list")
public class QuestionList implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToOne(fetch = FetchType.LAZY,cascade = {CascadeType.REFRESH,CascadeType.PERSIST})
private User owner;
@OneToMany(fetch = FetchType.LAZY,cascade = {CascadeType.REFRESH,CascadeType.PERSIST})
@JoinTable(name = "question_list_sent",
joinColumns = {@JoinColumn(name = "question_list_id",unique = false)},
inverseJoinColumns = {@JoinColumn(name = "question_id",unique = false)}
)
private List<Question> sent;
答案 0 :(得分:0)
你的JoinTable是OneToMany,这意味着一个QuestionList可以有多个Question,但每个Question只有一个QuestionList。要删除唯一约束,请使用JoinTable ManyToMany。