Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Database: Postgres 8.1
I have got a very strange performance problem with Hibernate.
Lets assume I have got a List with a bunch of Ids and want to query for their objects persited in my database.
Way 1 - The slow one:
Code:
Iterator it= idList.iterator();
while (it.hasNext()) {
Object obj = xyzDAO.getXyzById((Long)it.next());
}
This one creates several select statements with a response time of approx. 15ms to 30ms
Select statement from Hibernate looks like this:
Code:
select * from xyz where id = ?
..
..
Way 2 - The fast one:Code:
List obj = xyzDAO.getXyzByListOfIds(idList);
Here I create a query putting together an OR combined list and get back a List with my result objects.
The one Select statement from Hibernate looks like this:
Code:
select * from xyz where id = ? or id = ? or ....
This statement has a response time of approx. 15ms to 30ms. So this one statement delivers me the desired result in the time that one of the statements above from Way 1 needs.
If I have got 1000 ids to retrieve it would take in worst case 30ms*1000 to get them using the Way 1 and with Way 2 only 30ms.
Can anyone explain this performance problem?!?
[/code]