Hi Piet,

Piet Molenaar wrote:
Hi All,

I do not know whether this is desired behavior but when I use QueryByCriteria with an object that maps an inheritance hierarchy, only the fields specific for that object are queried (the javadocs state: Builds a Query based on anObject all non null values are used as EqualToCriteria). Consider the mapping below; there are specific detectionmethods (rnadetection, dnadetection) inheriting from a generic detectionmethod. This generic detectionmethod has a geneexptype; the specific rnadetection has a rnadetectiontype
When I now query the following

        RnaDetection detection = new RnaDetection();
        detection.setDetectiontype("Rna level");
        detection.setRnadetectiontype("Northern Blot");
        detection.setGeneexptype("Mutant on");

        QueryByCriteria q = new QueryByCriteria(evidence);

q.toString() now gives:

QueryByCriteria from class amcplugin.data.persistency.RnaDetection where [rnadetectiontype = Northern Blot]

This finds the wrong object as the fields geneexptype and detectiontype are not taken into consideration.... See below for descriptors and classes; maybe there's something wrong in the way I implement these using interfaces?

Seems your mapping is correct. You are using the real implementation classes in mapping and source.

Or is overriding equals, hashcode not allowed (till now I did not experience problems with that)

This shouldn't be a problem.

Seems that "query by example" only extract the fields of the current class all inherited fields (using 'table per subclass') seem to be ignored.

I set up a similar test with latest from SVN (OJB_1_0_RELEASE branch) using class Manager--->Executive--->Employee (with inheritance, base class is Employee). The test fail when set inherited fields in the example object.
Checked in a fix some minutes ago (JIRA: OJB-128).

Using the Criteria-API the test pass.
The Criteria looks like these:
String name = "testComplexQuery_" + timestamp;
Criteria crit = new Criteria()
     .addLike("executives.name", "%" + name)
     .addEqualTo("name", "manager_" + name)
     .addIsNull("department")
     .addIsNull("manager")
     .addIsNull("address");
Query q = QueryFactory.newQuery(Manager.class, crit);

The field 'executives' is defined in Manager class, fields 'department' and 'manager' are declared in Executive, field 'name' and 'address' are declared in Employee. Think this is similar to your test and could be a workaround. All fields are be included in the the generated query.

The Criteria.toString log:
crit: [executives.name LIKE %testComplexQuery_1169638422671, name = manager_testComplexQuery_1169638422671, department IS NULL , manager IS NULL , address IS NULL ]

And the generated SQL looks like:

SELECT A0.OBJ_ID,A0.OBJ_ID_2,A0.FK_CONSORTIUM,A1.OBJ_ID,A1.OBJ_ID_2,A1.DEPARTMENT,A1.MANAGER_ID,A1.MANAGER_ID_2,A2.OBJ_ID,A2.OBJ_ID_2,A2.NAME,A2.FK_ADDRESS,A3.OBJ_ID,A3.OBJ_ID_2,A3.SHARE_,CASE WHEN A3.OBJ_ID IS NOT NULL AND A3.OBJ_ID_2 IS NOT NULL THEN 'org.apache.ojb.broker.InheritanceMultipleTableTest$Shareholder' ELSE 'org.apache.ojb.broker.InheritanceMultipleTableTest$Manager' END AS OJB_CLAZZ FROM INH_MANAGER A0 INNER JOIN INH_EXECUTIVE A1 ON A0.OBJ_ID=A1.OBJ_ID AND A0.OBJ_ID_2=A1.OBJ_ID_2 INNER JOIN INH_EMPLOYEE A2 ON A1.OBJ_ID=A2.OBJ_ID AND A1.OBJ_ID_2=A2.OBJ_ID_2 LEFT OUTER JOIN INH_SHAREHOLDER A3 ON A0.OBJ_ID=A3.OBJ_ID AND A0.OBJ_ID_2=A3.OBJ_ID_2 INNER JOIN INH_EXECUTIVE A4 ON A0.OBJ_ID=A4.MANAGER_ID AND A0.OBJ_ID_2=A4.MANAGER_ID_2 INNER JOIN INH_EMPLOYEE A5 ON A4.OBJ_ID=A5.OBJ_ID AND A4.OBJ_ID_2=A5.OBJ_ID_2 WHERE ((((A2.NAME LIKE '%testComplexQuery_1169638422671') AND A2.NAME = 'manager_testComplexQuery_1169638422671') AND A1.DEPARTMENT IS NULL ) AND A1.MANAGER_ID IS NULL ) AND A2.FK_ADDRESS IS NULL

If this doesn't work with your release, please try latest source from SVN - if possible (source is stable). We plan to release OJB 1.0.5 by the end of this month (wait for RC1 of DdlUtils project to include this jar).

regards,
Armin


Thanks in advance!

Piet




   <class-descriptor
      class="amcplugin.data.persistency.DetectionMethod"
      table="DETECTION_METHOD"
   >
      <field-descriptor id="1"
         name="methodid"
         column="METHOD_ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
      />
      <field-descriptor id="2"
         name="detectiontype"
         column="DETECTION_TYPE"
         jdbc-type="VARCHAR"
      />
      <field-descriptor id="3"
         name="geneexptype"
         column="GENE_EXP_TYPE"
         jdbc-type="VARCHAR"
      />
   </class-descriptor>

   <!-- RnaDetection describes the method of detection on rna level -->
   <class-descriptor
      class="amcplugin.data.persistency.RnaDetection"
      table="RNA_DETECTION"
   >
      <field-descriptor id="1"
         name="methodid"
         column="METHOD_ID"
         jdbc-type="INTEGER"
         primarykey="true"
      />
      <field-descriptor id="2"
         name="rnadetectiontype"
         column="RNA_DETECTION_TYPE"
         jdbc-type="VARCHAR"
      />
      <reference-descriptor name="super"
         class-ref="amcplugin.data.persistency.DetectionMethod"
      >
         <foreignkey field-ref="methodid"/>
      </reference-descriptor>
   </class-descriptor>


public class DetectionMethod implements DetectionMethodInterface
{
    private volatile int hashCode = 0;
    public static String METHOD_ID = "methodid";
    public static String GENE_EXP_TYPE = "geneexptype";
    public static String DETECTION_TYPE = "detectiontype";
    protected Integer methodid;
    protected String geneexptype;
    protected String detectiontype;

    public DetectionMethod()
    {
        this.setDetectiontype("Not specified");
        this.setGeneexptype("Not specified");
    }

    public String getGeneexptype()
    {
        return geneexptype;
    }

    public void setGeneexptype(String geneexptype)
    {
        this.geneexptype = geneexptype;
    }

    public String getDetectiontype()
    {
        return detectiontype;
    }

    public void setDetectiontype(String detectionlevel)
    {
        this.detectiontype = detectionlevel;
    }

    /**
     * @return Returns the methodid.
     */
    public Integer getMethodid()
    {
        return methodid;
    }

    public void setMethodid(Integer methodid)
    {
        this.methodid = methodid;
    }

    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getDetectiontype());
        return sb.toString();
    }

    /**
     * Override to compare dataobjects
     *
     * @return
     */
    public boolean equals(Object o)
    {
        if (o == this)
            return true;
        if (o != null && o.getClass().equals(this.getClass()))
        {
            DetectionMethod other = (DetectionMethod) o;
return ((this.detectiontype == other.detectiontype) || (this.detectiontype != null)
                    && this.detectiontype.equals(other.detectiontype))
&& ((this.geneexptype == other.geneexptype) || (this.geneexptype != null)
                            && this.geneexptype.equals(other.geneexptype));
        }
        else
            return false;
    }

    /**
     * When equals overridden than hashCode also
     */
    public int hashCode()
    {
        if (hashCode == 0)
        {
            int dl, ge;
            if (this.detectiontype == null)
                dl = 0;
            else
                dl = this.detectiontype.hashCode();
            if (this.geneexptype == null)
                ge = 0;
            else
                ge = this.geneexptype.hashCode();
            int result = 17;
            result = 37 * result + dl;
            result = 37 * result + ge;
            hashCode = result;
        }
        return hashCode;
    }
}


public interface DetectionMethodInterface {
    public String getDetectiontype();
    public void setDetectiontype(String detectionlevel);
    public String getGeneexptype();
    public void setGeneexptype(String hostproperties);
    public Integer getMethodid();
    public void setMethodid(Integer methodid);
}

public class RnaDetection extends DetectionMethod implements RnaDetectionInterface
{
    public static String RNA_DETECTION_TYPE = "rnadetectiontype";
    private volatile int hashCode = 0;
    protected String rnadetectiontype;

    public RnaDetection()
    {
        super();
        super.setDetectiontype("Rna level");
        this.setRnadetectiontype("Unspecified");
    }

    public String getRnadetectiontype()
    {
        return rnadetectiontype;
    }

    public void setRnadetectiontype(String rnadetectiontype)
    {
        this.rnadetectiontype = rnadetectiontype;
    }

    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        sb.append(getRnadetectiontype());
        sb.append("::");
        sb.append(super.toString());
        return sb.toString();
    }

    /**
     * Override to compare dataobjects
     *
     * @return
     */
    public boolean equals(Object o)
    {
        if (o == this)
            return true;
        if (o != null && o.getClass().equals(this.getClass()))
        {
            RnaDetection other = (RnaDetection) o;
return ((this.detectiontype == other.detectiontype) || (this.detectiontype != null)
                    && this.detectiontype.equals(other.detectiontype))
&& ((this.geneexptype == other.geneexptype) || (this.geneexptype != null)
                            && this.geneexptype.equals(other.geneexptype))
&& ((this.rnadetectiontype == other.rnadetectiontype) || (this.rnadetectiontype != null) && this.rnadetectiontype.equals(other.rnadetectiontype));
        }
        else
            return false;
    }

    /**
     * When equals overridden than hashCode also
     */
    public int hashCode()
    {
        if (hashCode == 0)
        {
            int dl, ge, rdt;
            if (this.detectiontype == null)
                dl = 0;
            else
                dl = this.detectiontype.hashCode();
            if (this.geneexptype == null)
                ge = 0;
            else
                ge = this.geneexptype.hashCode();
            if (this.rnadetectiontype == null)
                rdt = 0;
            else
                rdt = this.rnadetectiontype.hashCode();
            int result = 17;
            result = 37 * result + dl;
            result = 37 * result + ge;
            result = 37 * result + rdt;
            hashCode = result;
        }
        return hashCode;
    }

public interface RnaDetectionInterface extends DetectionMethodInterface {
    public String getRnadetectiontype();
    public void setRnadetectiontype(String rnadetectiontype);
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to