JPA继承有问题,服务器抛出错误。关于这个主题已经有很多问题,但是我找不到解决问题的方法,所以这里有关于我目前所拥有的细节......
超类:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name = "PERSON_TYPE", discriminatorType = DiscriminatorType.INTEGER)
@Table(name = "PERSON")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRIGGER_PERSON_PRIMARY_KEY")
@SequenceGenerator(name = "TRIGGER_PERSON_PRIMARY_KEY", sequenceName = "PERSON_AI_SEQUENCE", allocationSize = 1, initialValue = 1)
@Column(name = "PERSON_ID", updatable = false, unique = true, nullable = false)
protected int personId;
子类:
@Entity
@Table(name = "APPLICANT")
@DiscriminatorValue(value = "1")
@PrimaryKeyJoinColumn(name="APPLICANT_ID")
public class Applicant extends Person {
}
错误消息:
The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
Caused by: java.lang.ClassCastException: org.hibernate.mapping.UnionSubclass cannot be cast to org.hibernate.mapping.RootClass
答案 0 :(得分:0)
super 类和 sub 类中不能有@Id
。
<强>解决方案强>
从子类@Id
Applicant
更多信息:
答案 1 :(得分:0)
我终于设法解决了这个问题。我采取了几个步骤: