如何在具有不同目标实体的多个子类中的超类getter方法上应用@OneToMany

时间:2017-05-19 11:09:53

标签: eclipselink jpa-2.0 one-to-many

堆栈

我正在使用JPA2.0和Eclipselink 2.6.3以及Spring 4(JTA)。

问题

我正在尝试使用类B和类C中的@OneToMany映射覆盖类A属性(类似于类B),这样我可以在获取类的结果时分别将目标实体更改为类X和Z乙

A类具有SINGLE_TABLE继承和B类和B类。 C是鉴别器类,由@classExtractor维护,具体取决于A类中的某些字段值。

Z类具有TABLE_PER_CLASS继承和类X& Y使用相同的表扩展了Z类(只是为了避免DTYPE而继承hack)。

预期结果 当我在B类或C类上查询并获取getZList()时,我应该能够看到类B和B中的@OneToMany映射中的targetEntity中提到的类X和Y类型对象。 C

我尝试在下面的子类中重写A类的getter,但列表总是为空。

A类

@Entity
@Table(name="TABLE_A")
@Customizer(ACustomizer.class)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@ClassExtractor(AExtractor.class)
@InstantiationCopyPolicy
@Cacheable
@Cache( alwaysRefresh=true,
        refreshOnlyIfNewer=true,
        expiry=300000,      
        coordinationType = CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES)
public class A implements Serializable {
@Column(name="ABC")
private String abc;
@Transient
private List zlist= new ArrayList<>();

}

B类

@Entity
public class B extends A{
//problem is here...this mappping doesn't populate super class object 
@Access(AccessType.PROPERTY)
    @OneToMany(cascade=CascadeType.ALL, mappedBy="class A", targetEntity=Z.class)
    @PrivateOwned 
    public List getZList() {
        return super.getZList();
    }
}

Z级

@Entity
@Table(name="TABLE_Z")
@Customizer(ZCustomizer.class)
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Z{
 //some fields 
//and @oneToOne mapped with class A
}

第X类

 @Table(name="TABLE_Z")
   @Entity
    public class X extends Z{
     //some fields 

    }

0 个答案:

没有答案
相关问题