I have a fairly simple use case where I've implemented this:
Code:
Main.log.debug("Executing SQL...");
String sql = "SELECT * FROM theTable";
ResultSet rs = null;
try {
rs = sth.executeQuery(sql);
} catch (SQLException ex) {
ex.printStackTrace();
}
int count = 0;
try {
while (rs.next()) {
/* Do nothing */
count++;
}
} catch (SQLException ex) {
ex.printStackTrace();
}
I had Netbeans 5.5.1 generate an Entity Class for
theTable backed with Hibernate + Annotions + EntityManager and then executed this:
log.debug("Creating query now...");
Code:
Query q = em.createNamedQuery("TheTable.all");
log.warn("Retrieving list...");
long before = System.currentTimeMillis();
List l = q.getResultList();
int count = l.size();
That named Query is:
Code:
@NamedQuery(name = "TheTable.all" query = "SELECT m FROM TheTable m"),
Now:
1. The JDBC takes about 3-5 seconds
2. The Hibernate / JPA version takes about 19-20 seconds
As a side note, I had:
1. Perl plain DBI take about 4-5 seconds
2. Rose::DB::Object with a manager took < 1 second to count them
* but iterating took about 4-5 seconds
I did attempt to force almost all the rows on the TheTable to be lazy load and this didn't seem to make a difference. Using a DB connection pool seemed to make no difference.
Any comments?
DSL