Java 如何保持具有重复列的继承关系

Java 如何保持具有重复列的继承关系,java,hibernate,jpa,Java,Hibernate,Jpa,我有此代码与继承关系: @Entity @Table(name = "PERSON") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "PERSON_TYPE", discriminatorType = DiscriminatorType.STRING, length = 4) public abstract class Person implements Serializable {

我有此代码与继承关系:

@Entity
@Table(name = "PERSON")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "PERSON_TYPE", discriminatorType = DiscriminatorType.STRING, length = 4)

public abstract class Person implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ID_PERSON_ID")
private Long id;

...other attributes
}

@Entity
@Table(name="STUDENT")
@DiscriminatorValue(value = "STUD")
public class Student extends Person implements Serializable{

@OneToMany(targetEntity = ListingRatings.class, mappedBy = "student", cascade=CascadeType.ALL, orphanRemoval=true)
private List<ListingRatings> listingRatings;

...other attributes

}

@Entity
@Table(name="LISTING_RATING")
public class ListingRatings implements Serializable{

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ID_LISTING_RATING_ID")
private Long id;

@ManyToOne(targetEntity = Teacher .class, optional = false )
@JoinColumn(name = "ID_PERSON_ID", referencedColumnName = "ID_PERSON_ID",                      insertable=true , updatable=true )
private Teacher teacher;

@ManyToOne(targetEntity = Student.class, optional = false )
@JoinColumn(name = "ID_PERSON_ID", referencedColumnName = "ID_PERSON_ID")
private Student student;

...other attributes
}

@Entity
@Table(name="TEACHER")
@DiscriminatorValue(value="TEAC")
public class Teacher extends Person implements Serializable{

@OneToMany(targetEntity = ListingRatings .class, mappedBy = "teacher",    fetch=FetchType.EAGER)
private List<ListingRatings> listingRatings ;

}
当我试图保持这种关系时,我有一个例外

原因:org.hibernate.MappingException:实体映射中的重复列: cl.programarte.gym.model.Listings 列:ID\u PERSON\u ID应映射为insert=false update=false

我不知道这是否可能。 将insertable=true、updateable=true更改为insertable=false、updateable=false,一切正常。 然而,我需要坚持教师的id,但这不是

也许可以为这种情况制作一个复合密钥? 这是推荐给你的吗


非常感谢。

为什么要使用相同的联接列名来映射两个不同的关联?你显然需要两个不同的栏目,因为一个列表的老师和他的学生不是同一个人。非常感谢你,在发布问题后,我发现了我的错误。顺致敬意,