RE: BUGREPORT : OJB 1.0.5 - count query in combination with IN-clause

"Janssen, Roger" <[email protected]> Wed, 30 Jan 2008 10:09:28 +0100
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi,

Some code examples to reproduce the count-query bug in combination with
an IN-clause. These are excerpts from our own test suite so they use
some of hour domain classes and properties of these classes, so you have
to modify this example using the domain classes from the OJB testsuite
to run them in there.

(below: the 'pb' object is a PersistenceBroker instance)
The first example is a query retrieving a collection, that one works!

            Vector v = new Vector();
            v.add(new String("PAS/104"));
            v.add(new String("PAS/105"));
            v.add(new String("PAS/106"));

            Criteria crit_in = new Criteria().addIn("workOrderNr", v);
            Query in_query = QueryFactory.newQuery(Permit.class,
crit_in, true);
            Collection c = pb.getCollectionByQuery(in_query) ;

The second example builds the same query but executes a count, that one
crashes:

		Vector v = new Vector();
            v.add(new String("PAS/104"));
            v.add(new String("PAS/105"));
            v.add(new String("PAS/106"));

            Criteria crit_in = new Criteria().addIn("workOrderNr", v);
            Query in_query = QueryFactory.newQuery(Permit.class,
crit_in, true);
            int count = pb.getCount(in_query);


Some errormessage feedback is:

* SQLException during execution of sql-statement:
* sql statement: select count(*) from (SELECT DISTINCT A0.ID FROM
IBANX_PERMIT A0 WHERE null ) ojb_enc
* Exception message: Not a condition in statement [select count(*) from
(SELECT DISTINCT A0.ID FROM IBANX_PERMIT A0 WHERE null ) ojb_enc]
* Vendor error code: -106
* SQL state code: S1000
**

The stacktrace is:

java.sql.SQLException: Not a condition in statement [select count(*)
from (SELECT DISTINCT A0.ID FROM IBANX_PERMIT A0 WHERE null ) ojb_enc]
        at org.hsqldb.jdbc.Util.throwError(Unknown Source)
        at org.hsqldb.jdbc.jdbcPreparedStatement.executeQuery(Unknown
Source)
        at
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown
Source)
        at
org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown
Source)
        at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown
Source)
        at
org.apache.ojb.broker.accesslayer.ReportQueryRsIterator.<init>(Unknown
Source)
        at
org.apache.ojb.broker.core.ReportRsIteratorFactoryImpl.createRsIterator(
Unknown Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(
Unknown Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getReportQueryIteratorF
romQuery(Unknown Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getReportQueryIteratorB
yQuery(Unknown Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCount(Unknown
Source)
        at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCount(Unknown
Source)
        at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCount(Unknown
Source)
        at
ibanx.persistence.test.OJBTest.testCountQueryCriteriaInOJB(OJBTest.java:
306)


It is obvious that the count-query lost the where clauses!

Hope this helps.

Roger Janssen
*************************************************************************
The information contained in this communication is confidential and is intended solely for the use of the individual or entity to  whom it is addressed.You should not copy, disclose or distribute this communication without the authority of iBanx bv. iBanx bv is neither liable for the proper and complete transmission of the information has been maintained nor that the communication is free of viruses, interceptions or interference. 

If you are not the intended recipient of this communication please return the communication to the sender and delete and destroy all copies.