Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance JPA 2 Inheritation.TABLE_每个类具有抽象关系_Inheritance_Jpa_Jpa 2.0_Java Ee 6_One To Many - Fatal编程技术网

Inheritance JPA 2 Inheritation.TABLE_每个类具有抽象关系

Inheritance JPA 2 Inheritation.TABLE_每个类具有抽象关系,inheritance,jpa,jpa-2.0,java-ee-6,one-to-many,Inheritance,Jpa,Jpa 2.0,Java Ee 6,One To Many,我拥有以下实体: @Entity public class Owner{ @Id @Column(name = "OWNER_ID") @OneToMany() @JoinColumn(name = "OWNER_ID") private Set<Parent> parents; ... } @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class P

我拥有以下实体:

@Entity
public class Owner{
@Id
@Column(name = "OWNER_ID")

    @OneToMany()
    @JoinColumn(name = "OWNER_ID")
    private Set<Parent> parents;
    ...
}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Parent{
    @Id
    @Column(name = "PARENT_ID")
    ...
}

@Entity
public class ChildA extends Parent{
    ...
}

@Entity
public class ChildB extends Parent{
    ...
}
@实体
公共类所有者{
@身份证
@列(name=“OWNER\u ID”)
@OneToMany()
@JoinColumn(name=“OWNER\u ID”)
私人家长;
...
}
@实体
@继承(策略=继承类型。每个类的表)
公共类父类{
@身份证
@列(name=“PARENT\u ID”)
...
}
@实体
公共类ChildA扩展了父类{
...
}
@实体
公共类ChildB扩展了父类{
...
}
}

问题是,当我尝试使用父元素持久化所有者时,会出现以下异常:

org.springframework.dao.InvalidDataAccessResourceUsageException:无法插入集合:[sample.Owner.parents#1];SQL[更新父集合所有者\ ID=?其中父\ ID=?];org.springframework.dao.InvalidDataAccessResourceUsageException:无法插入集合:[sample.Owner.parents#1];SQL[更新父集合所有者\ ID=?其中父\ ID=?];嵌套异常为org.hibernate.exception.sqlgrammareexception:无法插入集合: [sample.Owner.parents#1]嵌套异常为org.hibernate.exception.sqlgrammareexception:无法插入集合:[sample.Owner.parents#1]


如果我将InheritanceType更改为JOINED,它可以正常工作。关于为什么要持久化父抽象类而不是子抽象类,您有什么想法吗?

Hibernate要求每个类层次结构表的多态关联是双向的():

公共类所有者{
@OneToMany(mappedBy=“所有者”)
私人家长;
...
}
公共clas家长{
...
@许多酮
@JoinColumn(name=“OWNER\u ID”)
私人业主;
...
}

非常感谢,你真的拿到了银弹。
public class Owner {
    @OneToMany(mappedBy = "owner")
    private Set<Parent> parents;
    ...
}

public clas Parent {
    ...
    @ManyToOne
    @JoinColumn(name = "OWNER_ID")
    private Owner owner;
    ...
}