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 Joerg Heinicke <jo...@gmx.de> on 2004/08/11 14:47:44 UTC

[OTM] problem with subcriteria

I want to retrieve some special objects from db where I need a
subquery/subcriteria, but I don't get it to work. I followed the guide at
http://db.apache.org/ojb/docu/guides/query.html#subqueries (or its older version
delivered with OJB 1.0, but nothing seems to have changed).

My objects and their relations: I have a Legalcase which has a collection of
LegalcaseEvents which is an abstract class and has some extending classes. All
the events have a date field. I want to retrieve all legalcases with a specific
commission date, which means the date of a New.class extending LegalcaseEvent.

My code looks like the following:

Criteria criteria = new Criteria();
Criteria subCrit = new Criteria();

subCrit.addEqualToField("legalcaseId", Criteria.PARENT_QUERY_PREFIX + "id");

// Here I don't know if it must be LegalcaseEvent.class or its extending version
New.class
ReportQueryByCriteria subQuery = QueryFactory.newReportQuery(New.class, subCrit);

subQuery.setAttributes(new String[] { "date" });

criteria.addGreaterOrEqualThan(subQuery, commissionDate);

QueryByCriteria q = QueryFactory.newQuery(Legalcase.class, criteria, true);

Iterator iter = conn.getIteratorByQuery(q);

When using LegalcaseEvent.class in the above commented line I get a NPE (in
org.apache.ojb.broker.accesslayer.sql.SQLQueryStatement, line 1920, the table
alias for the class LegalcaseEvent is null), when using New.class I get "No
value specified for parameter 3" which is the date (problem seems to be in wrong
binding in org.apache.ojb.broker.accesslayer.StatementManager.
bindStatementValue(), line 189, fld in line 208 remains null for the value of
type java.util.Date, so flow goes to line 227 (which has no effect on the
prepared statement) instead of line 216 where it probably has to go). Now I
don't know if my criteria code is wrong or the OJB criteria 2 sql code.

Another problem is that there is a method addGreaterOrEqualThan(Object, Object)
and a method addLessOrEqualThan(Object, Object), but no addEqualTo(Object,
Object), so I would need two comparisons (>= and =< instead of one exact match).

I would appreciate any help.

Jörg


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