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

Piet Molenaar <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
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: [email protected]
>For additional commands, e-mail: [email protected]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.