javaormjdodatanucleusjdoql

How to remove discriminators from where clause in request?


I have a parent class declared like that:

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

and some inherited classes like this one:

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

For no reason, Datanucleus uses the discrimnator in the where clause of the sql requests that he generates like this one:

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

How can I say to Datanucleus to not use the discriminator (classId) in his requests?


Solution

  • There is a very good reason why a discriminator is added by default to such queries ... because you defined a discriminator on that class (and subclasses/superclasses), and also because your query may not include all classes in that inheritance tree. Similarly, what if you are persisting some data into those tables and using different discriminator values to isolate that data from what your JDO layer uses?

    Certainly in the docs for version 5.2 I see a query extension (dont-restrict-discriminator) that can be used to override the default. No idea whether that is in earlier versions.