如何从请求中的 where 子句中删除鉴别符?

How to remove discriminators from where clause in request?

我有一个 parent class 声明如下:

@PersistenceCapable(table = "S_ROT_CLASS")
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
@Discriminator(strategy = DiscriminatorStrategy.VALUE_MAP, column = "CLASS_ID", value = "300")
@FetchGroup(name = Constants.LAZY_LOAD_GROUP_FETCH_PLAN, members = { @Persistent(name = "classId"),
        @Persistent(name = "objId") })
public class DBObject {

    @Persistent(dependent = "false")
    @Column(name = "S_ROT_CREATE_USR_ID")
    private DBUser createdBy;

    @Persistent(dependent = "false")
    @Column(name = "S_ROT_USR_ID")
    private DBUser lastUpdateBy;

    @Column(name = "CLASS_ID")
    @Extension(vendorName = "datanucleus", key = "insertable", value = "false")
    @Extension(vendorName = "datanucleus", key = "updateable", value = "false")
    private long classId;

    @PrimaryKey
    @Column(name = "OBJ_ID")
    private long objId;

   public DBObject() {
        super();
        setClassId(300);
    }

    //with getters and setters
}

还有一些像这样继承的 classes:

@PersistenceCapable(table="S_PMG_CLASS")
@Inheritance(strategy=InheritanceStrategy.NEW_TABLE)
@Discriminator(value="330")
public class DBUserGroup extends DBObject{

    @Column(name="CLASS_ID")
    private long classId330;

    @Column(name="OBJ_TYPE")
    private long objType330;
 public DBUserGroup(){
        super();
        setClassId(330);
    }

//with getters and setters
}

无缘无故,Datanucleus 在他生成的 sql 请求的 where 子句中使用了鉴别符,如下所示:

SELECT A0.CLASS_ID, A0.OBJ_ID, A0.CLASS_ID
  FROM S_ROT_CLASS A0
 WHERE ( (   A0.CLASS_ID = '300'
          OR A0.CLASS_ID = '1230985'
          OR A0.CLASS_ID = '44267844'
          OR A0.CLASS_ID = '44267843'
          OR A0.CLASS_ID = '1230798'
          OR A0.CLASS_ID = '6744896'
          OR A0.CLASS_ID = '44267842'
          OR A0.CLASS_ID = '1230719'
          OR A0.CLASS_ID = '39132351'
          OR A0.CLASS_ID = '150031398'
          OR A0.CLASS_ID = '65607622'
          OR A0.CLASS_ID = '1230818'
          OR A0.CLASS_ID = '1230795'
          OR A0.CLASS_ID = '1230744'
          OR A0.CLASS_ID = '104595125'
          OR A0.CLASS_ID = '18699812'
          OR A0.CLASS_ID = '44303147'
          OR A0.CLASS_ID = '44303146'))
       AND A0.S_ROT_CREATE_USR_ID = 125874

我如何告诉 Datanucleus 在他的请求中不要使用鉴别器 (classId)?

默认情况下向此类查询添加鉴别器是有充分理由的...因为您在 class(和 subclasses/superclasses)上定义了鉴别器,还因为您的查询可能不包括该继承树中的所有 classes。同样,如果您将一些数据持久化到这些表中并使用不同的鉴别器值将该数据与您的 JDO 层使用的数据隔离开来怎么办?

当然在 5.2 版本的文档中 I see a query extension (dont-restrict-discriminator) 可用于覆盖默认值。不知道这是否在早期版本中。