@oneToMany实体中的TABLE_PER_CLASS继承策略提供重复结果

时间:2017-05-31 08:59:46

标签: jpa eclipselink jpa-2.0

Eclipselink 2.6.3 with JPA 2.0

我有一个TABLE_PER_CLASS继承策略的问题,你可以看到我有一个类A,它有@oneToMany映射和类Z,它有TABLE_PER_CLASS,X和Y作为子类,所有类(X,Y,Z)都有相同的表名称即TABLE_Z。

当我在类上查询并获取zlist的结果时,它具有与所有三个类X,Y,Z重复相同的数据,但是我只需要在将目标实体映射为类Z时提到的类Z.

有人能指出我做错了吗?

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;
//the problem is with this relationship...fetches multiple objects for same data with X,Y,Z classes
@OneToMany(cascade=CascadeType.ALL, mappedBy="aobj", targetEntity=Z.class)
private List zlist= new ArrayList<>();

}

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 个答案:

没有答案