I have a problem with my mapping OneToMany. My exception is
org.hibernate.MappingException:实体映射中的重复列:com.lcdut.model.SubjectsModel column:groups(应使用insert =“false”update =“false”映射)
@Entity
@Table(name = "subjects")
public class SubjectsModel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name = "groups")
private int groups;
...........
@ManyToOne
@JoinColumns({
@JoinColumn(name="groups", referencedColumnName="id_group")
})
private StudentsModel studentsModel;
........
}
@Entity
@Table(name = "students")
public class StudentsModel{
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Basic
@Column(name = "pib")
private String pib;
@Basic
@Column(name = "id_group")
........
@OneToMany(mappedBy = "studentsModel")
private Set<SubjectsModel> subjects;
}
答案 0 :(得分:-1)
您已告诉Hibernate groups
列的值来自原始属性groups
以及关系映射studentsModel
。这是非法的,只有一个可以影响价值。
您需要将groups
映射指定为:
@Column(name = "groups", insertable = false, updatable = false)
或者您可以指定studentsModel
是:
@JoinColumn(
name = "groups",
referencedColumnName = "id_group",
insertable = false,
updatable = false
)
或最后删除原始属性并仅通过关系@ManyToOne
映射来影响该值,而无需更改注释。