1

Eclipselink 2.6.3 with JPA 2.0

I have an issue with TABLE_PER_CLASS inheritance strategy as you can see I have class A which has @oneToMany mapping with Class Z which has TABLE_PER_CLASS with X and Y as child classes all the classes(X,Y,Z) have same table name i.e TABLE_Z.

When I query on class and I fetch the result of zlist it has same data repeated with all three classes X,Y,Z but I need only class Z as I mentioned in mapping target entity as class Z.

Can anyone point me what I'm doing wrong?

Class 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<>();

}

Class 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
}

class X

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

    }
ngCoder
  • 2,095
  • 1
  • 13
  • 22
  • similar to question https://stackoverflow.com/questions/4256393/jpa-table-per-class-inheritance-how-to-only-select-superclass-entries?noredirect=1&lq=1 – ngCoder May 31 '17 at 10:08
  • duplicate of https://stackoverflow.com/questions/44068524/how-to-apply-onetomany-on-super-class-getter-method-in-multiple-subclasses-with#comment75565845_44068524 This shouldn't be using table per class inheritance unless subclasses are going to use their own tables. Putting them all in "TABLE_Z" should have it configured to use single table inheritance, and JPA needs a way to tell which row belongs to which subclass. – Chris May 31 '17 at 17:33

0 Answers0