EclipseLink DescriptorCustomizer不支持继承的子类型吗?

时间:2015-01-27 21:44:06

标签: java jpa eclipselink

基本上,我有一个基类类型,它将实体描述为不可删除。我使用eclipse链接的描述符定制程序API来覆盖默认的删除SQL,并添加其他条件以仅返回非归档实体。

这适用于直接扩展Archiveable类的所有类。扩展非MappedSuperClass以扩展Archiveable类的类不会继承自定义程序。请参阅下面的示例:

对于它的价值,我使用的是EclipseLink 2.5.1。

/**
 * Base Abstract class that implements archiving functionality 
 */ 
@MappedSuperClass
@Customizer(ArchiveableCustomizer.class)
public abstract class Archiveable {

   @NotNull
   @Column(name = "DELETED)
   private Boolean archived = false;    

   // omitted: getters/setters    
}

/**
 * The EclipseLink customizer implementation (followed their docs)
 */ 
public class ArchiveableCustomizer extends DescriptorEventAdapter
        implements DescriptorCustomizer {

     @Override
     public void customize(ClassDescriptor descriptor) throws Exception {
         // omitted: override delete string

         // this is the piece not working
         descriptor.getQueryManager().setAdditionalCriteria("this.archived = false");
     }
}


/**
 * Base class for entities that are stored in the Catalog table. All are archived
 */ 
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", DiscriminatorType.STRING)
public abstract class Catalog extends Archiveable {
    // omitted: shared columns, not relevant. 
}

/**
 * This class does <b>NOT</b> work
 */
@Entity 
@DiscriminatorValue("CAR_TYPE")
public class CarType extends Catalog {
    // omitted: class details, not relevant
}

/**
 * Class that does not extend the Catalog class but the Archiveable 
 * class directly. This class can be queried correctly with the 
 * additional criteria
 */ 
@Entity
public class Car extends Archiveable { 
     // omitted: clas details, not relevant
}

总之,课程CarType 选择ArchiveableCustomizer。班级Car 会选择ArchiveableCustomizer

1 个答案:

答案 0 :(得分:1)

在EclipseLink的内部,MappedSuperClass类本身没有描述符,因此所有设置都从它们中提取并应用于子类实体描述符 - 包括定制器。

通过继承,层次结构中的每个实体都有自己的描述符,并且在继承映射和其他设置时,描述符定制器仅在它们分配给的描述符上执行 - 在本例中为根。另请注意,根类中的某些更改将在子类中看到;例如,继承图都使用相同的缓存,虽然我不确定这一点,但子编辑器上可能会看到对公共映射的更改