Java JPA-表每类继承-Id冲突
我有一个带有ID字段的父类和两个子类。我已经为每个类继承应用了表。 这两个表中的某些行具有相同的标识符。(同一身份证) 当调用JpaRepository的findAll()时,我有org.hibernate.PropertyAccessException 我能做些什么来解决冲突?我无法更改这些表中的ID,因为它们有很多依赖项和外键约束Java JPA-表每类继承-Id冲突,java,mysql,spring,hibernate,jpa,Java,Mysql,Spring,Hibernate,Jpa,我有一个带有ID字段的父类和两个子类。我已经为每个类继承应用了表。 这两个表中的某些行具有相同的标识符。(同一身份证) 当调用JpaRepository的findAll()时,我有org.hibernate.PropertyAccessException 我能做些什么来解决冲突?我无法更改这些表中的ID,因为它们有很多依赖项和外键约束 @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Parent implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@TableGenerator(name = "content_id_generator",
table = "generic_sequences",
pkColumnName = "sequence_name",
valueColumnName = "sequence_value",
pkColumnValue= "content_seq",
allocationSize = 20)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "content_id_generator")
@Column(updatable = false)
private Long id;
@Column(length = 250, nullable = false)
@NotNull
@Size(min = 1, max = 250)
private String title;
...
有Child1和Child2扩展父类的子类。
@Entity
@Table(name = "text_id_changed")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract class DependentCalss implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(updatable = false)
private Long id;
...
@Entity
@DiscriminatorValue("DependentCalssChild1")
public class DependentCalssChild1 extends DependentCalss {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "child_1_id")
private Child1 child1;
...
还有一个继承依赖于内容。
@Entity
@Table(name = "text_id_changed")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract class DependentCalss implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(updatable = false)
private Long id;
...
@Entity
@DiscriminatorValue("DependentCalssChild1")
public class DependentCalssChild1 extends DependentCalss {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "child_1_id")
private Child1 child1;
...
DependentCals有两个子类DependentCalsChild1和DependentCalsChild2。
@Entity
@Table(name = "text_id_changed")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract class DependentCalss implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(updatable = false)
private Long id;
...
@Entity
@DiscriminatorValue("DependentCalssChild1")
public class DependentCalssChild1 extends DependentCalss {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "child_1_id")
private Child1 child1;
...
及
和JPA假设
@Repository
public interface DependentCalssRepository extends JpaRepository<DependentCalss, Long> {
}
@存储库
公共接口依赖项CALSSrepository扩展了JpaRepository{
}
当我调用DependentCallsRepository的findAll()时,我捕捉到org.hibernate.PropertyAccessException该字段无法设置,等等
当Child1和Child2在不同的表中具有相同的ID时,就会发生这种情况。
我能做些什么来解决它?由于大量依赖项和约束,我无法更改表中的id。谢谢 您能提供父类的代码吗?已更新。谢谢您能提供父类的代码吗?已更新。谢谢