I have an Equipment class, with a unitYear attribute, which is stored in 
the database as a decimal field (e.g. 1994, 1995, 2004).
My repository descriptor for the Equipment class is:
<class-descriptor
    class="ca.richer.domain.Equipment"
    table="FDAAREP"
>
    <field-descriptor
        name="unitNumber"
        column="AAACNB"
        jdbc-type="VARCHAR"
        primarykey="true"
    >
    </field-descriptor>
    <field-descriptor
        name="unitYear"
        column="AAADNB"
        jdbc-type="DECIMAL"
    >
    </field-descriptor>
</class-descriptor>

I'd like to select all Equipment instances that are at least a certain 
age.  My OJB code is:
        Criteria criteria = new Criteria();
        criteria.addGreaterOrEqualThan("(year(current_date) - unitYear)", 
5);

        QueryByCriteria query = new QueryByCriteria(Equipment.class, 
criteria);

but this doesn't work ... it tells me that column unitYear is not an in 
the specified tables.  However, the following code *does* work:
        Criteria criteria = new Criteria();
        criteria.addGreaterOrEqualThan("(year(current_date) - AAADNB)", 
5);

        QueryByCriteria query = new QueryByCriteria(Equipment.class, 
criteria);

and so does this (albeit with the wrong results, but it proves that 
unitYear is mapped properly):
        Criteria criteria = new Criteria();
        criteria.addGreaterOrEqualThan("unitYear", 5);

        QueryByCriteria query = new QueryByCriteria(Equipment.class, 
criteria);

Is there some other way of doing this?  Why doesn't OJB resolve unitYear 
to its column name?

Thanks,
Phil

Reply via email to