I'm using some code similar to that listed below for batch updating a database. Note, I know that I should be using batch updates and that's what I plan on doing. However, setting aside updates, I want to know why I'm seeing slow performance with queries. When I run the following code on a data file which has about 23,000 rows in it and the rows already exist in the SQL table, for some reason the queries get progressively slower as it goes through the list of user ids. The user ids are in sorted order. The user id column in the table has a unique index on it and performance is good when updating the table using plain JDBC with SQL. Also, I noticed that the CPU is maxed out on the client when running the program while the CPU on the database server is low. I'm guessing that the problem is maybe cache related? I'm also seeing the following warning about ehcache which I'm wondering might have something to do with it. The other thing that I'm wondering is is maybe my hashCode() method might be implemented poorly. Currently, the hash code returned for the User class is just the id value of the object. I put debug statements in that method and it doesn't appear to be being called, so, I don't think that's what it is. Has anyone else run into this problem or have any ideas as to what might be the problem?
Feb 15, 2005 6:53:26 PM net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/hibernate-3.0beta4/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Hibernate version: hibernate-3.0beta4
Code between sessionFactory.openSession() and session.close():
Code:
Query q = s.createQuery("from User u where u.userId = :userId");
while(s2 != null) {
Matcher m = p.matcher(s2);
m.matches();
String userId = m.group(1);
List<User> l = q.setParameter("userId", userId).list();
s2 = br.readLine();
}
Name and version of the database you are using: MySQL 4.0.13
The generated SQL (show_sql=true):
select user0_.id as id, user0_1_.userId as userId2_, user0_1_.department as department2_, user0_1_.emailAddress as emailAdd4_2_, user0_1_.firstName as firstName2_, user0_1_.lastName as lastName2_, user0_1_.middleName as middleName2_, user0_1_.telephoneNumber as telephon8_2_, user0_1_.buildingName as building9_2_, user0_1_.city as city2_, user0_1_.roomNumber as roomNumber2_,
user0_1_.stateAbbreviation as stateAb12_2_, user0_1_.streetAddress as streetA13_2_, user0_1_.ZIPCode as ZIPCode2_, user0_1_.name as name2_, user0_1_.title as title2_, user0_1_.organization as organiz17_2_, user0_.userId as userId4_ from User_ user0_ inner join Person user0_1_ on user0_.id=user0_1_.id where (user0_1_.userId=? )