[英]How to get inheritance entity by using joined sub entity in jpa?
Writing the case it will be more simple to explain. 编写案例将更容易解释。
I am using Seam 2.3.1 v Hibernate JPA 2.0 and in our project. 我在我们的项目中使用Seam 2.3.1 v Hibernate JPA 2.0。 I have a base
Person
Entity Class. 我有一个基本的
Person
Entity Class。
@Entity
@Name("person")
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "person")
public class Person extends BaseEntity {
private String name;
private String surName;
private String email;
private String phone;
// getter & setters
}
And I have 3 more Entity extends from Person as @Inheritance(strategy = InheritanceType.JOINED)
: Personel
, Musteri
, DisPaydas
我有3个实体从人扩展为
@Inheritance(strategy = InheritanceType.JOINED)
Personel
, Musteri
, DisPaydas
@Entity
@Name("personel")
public class Personel extends Person {
private String appellation;
// getter & setters
}
I want to List personels, musteris and dispaydas in my bean however when I set them in my Group Entity, I want to save them as Person. 我想在我的bean中列出人员,鼬和disdisdas,但是当我在组实体中设置它们时,我想将它们另存为Person。
In fact in DB there is no difference between person_id and personel_id, they are same. 实际上,在DB中person_id和personel_id之间没有区别,它们是相同的。 However when I listing it, they are
List<Personel>
但是,当我列出它时,它们是
List<Personel>
In summary: 综上所述:
I want to get List<Person>
from List<Personel>
or Person
from Personel
object. 我想从
List<Personel>
获得List<Person>
List<Personel>
或从Personel
对象获得Person
。
You're going to have to define an @Id
and @Column
in the Person
class for the person_id
. 您将必须在
Person
类中为person_id
定义一个@Id
和@Column
。
However, since the column has a different name in the child entity, you'll need to change it using an @AttributeOverride
to point to the personel_id
@Column
. 然而,由于该列中的子实体具有不同的名称,你需要使用去改变它
@AttributeOverride
指向personel_id
@Column
。
It couldn't hurt to use a @DiscriminatorColumn
in the parent and @DiscriminatorValue
in the children, but I don't think Hibernate requires those. 它不能伤害到使用
@DiscriminatorColumn
父和@DiscriminatorValue
的孩子,但我不认为Hibernate对那些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.