You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Piet Molenaar <p....@amc.uva.nl> on 2007/01/24 12:23:13 UTC

Re: QueryByCriteria not taking all non null fields in account with inheritance object

I'm sorry, but to avoid confusion; the line

QueryByCriteria q = new QueryByCriteria(evidence);

should be:

QueryByCriteria q = new QueryByCriteria(detection);


At 12:00 PM 1/24/2007, you 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?
>Or is overriding equals, hashcode not allowed (till now I did not 
>experience problems with that)
>
>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: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org