Hello all, I've written a CMP 2.0 entity bean, with a finder method
findAll() that returns a Collection of all instances of it from the
database. The EJB-QL associated with this query is a simple 'SELECT
Object(o) FROM table'.
When I run the findAll() method, I see the following queries in the
MySQL query log :
SELECT id FROM table;
SELECT field1, field2, field3 FROM table WHERE (id=1) OR (id=2) OR
(id=3) OR (id=4) OR (id=5) OR (id=6) OR (id=7) OR (id=8) OR (id=9) OR
(id=10) OR (id=11) ... etc.
The second query consists of 500+ OR clauses. Needless to say this is
horribly inefficient. This query takes ~13 seconds to execute, where
a simple 'SELECT field1, field2, field3 FROM table' takes .02 seconds
to execute.
I've tried overriding the EJB-QL with JBOSS-QL in the
jbosscmp-jdbc.xml DD file, but had the same results.
Can anyone provide some help/suggestions/additional reading, etc?
Thanks in advance,
Keith
Marek Lange - 04 Sep 2003 22:28 GMT
Keith Simeon schrieb:
> Hello all, I've written a CMP 2.0 entity bean, with a finder method
> findAll() that returns a Collection of all instances of it from the
[quoted text clipped - 21 lines]
> Thanks in advance,
> Keith
If it is necessary to execute findAll() you can use other loading
strategies (read-ahead etc.). However, consider to narrow your sql
request if possible. FindAll() is not the best idea if lots of rows are
returned.
-marek