I'm trying to use persistence broker queries within ODMG using OJB 0.9.7 as suggested in the FAQ. Queries using PersistenceBroker.getCollectionByQuery() work as suggested, but I'm not sure how to deal with those using getIteratorByQuery().

In OJB 0.9.4, the following fragment appeared to work (apart from not supporting extents). Note that the PB-level transaction is committed before the iterator is used:

Query query = new QueryByCriteria(Product.class, null);
broker.beginTransaction();
Iterator iter = broker.getIteratorByQuery(query);
broker.commitTransaction();
while (iter.hasNext())
{
System.out.println(iter.next());
}

(The real code also called Transaction.lock(item, tx.READ) on each item).

However, in OJB 0.9.7 this code produces an empty iterator. (Might that be a bug?). However it does produce the expected results if instead commitTransaction() happens at the end, or if the calls to beginTransaction() and commitTransaction() are omitted.

I originally put in the calls to beginTransaction() and commitTransaction() because the example in the FAQ has them surrounding the call to broker.getCollectionByQuery. So, my questions: are these calls actually needed in this context, where there are no updates deletes or inserts to the database? If so are they also needed when using getIteratorByQuery? And what about getReportQueryIteratorByQuery? What's the best approach?

Many thanks for any advice ...

John.



--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to