dho wrote:
Yes. What would be a more correct way to do the timing?
I don't know if it's more correct, but I created my own log4j logger with:
Code:
private Logger lgr = Logger.getLogger("com.paymentone.prototype.Prototype");
I use a log4j.properties that looks like this:
Code:
log4j.rootLogger = info, default
# uncomment this section to turn on console output
log4j.appender.default = org.apache.log4j.ConsoleAppender
log4j.appender.default.layout = org.apache.log4j.TTCCLayout
log4j.appender.default.layout.DateFormat = ABSOLUTE
This will give me time to the millisecond in my log output on the console. Then I put log statements before and after each query like so:
Code:
prototype.lgr.info("before queryDepartmentsHibernate");
hibernateList = prototype.queryDepartmentsHibernate();
prototype.lgr.info("after queryDepartmentsHibernate");
prototype.lgr.info("before queryDepartmentsJDBC");
jdbcList = prototype.queryDepartmentsJDBC();
prototype.lgr.info("after queryDepartmentsJDBC");
Here's the log output:
Code:
09:18:58,976 [main] INFO com.paymentone.prototype.Prototype - before queryDepartmentsHibernate
09:18:59,211 [main] INFO com.paymentone.prototype.Prototype - after queryDepartmentsHibernate
09:18:59,211 [main] INFO com.paymentone.prototype.Prototype - before queryDepartmentsJDBC
09:18:59,273 [main] INFO com.paymentone.prototype.Prototype - after queryDepartmentsJDBC
so both queryies ran in less than a second with 271 departments in my table.
The JDBC was a little faster, but all we did was run a query. If all you're going to do is run a query, then maybe straight JDBC would be the way to go.
But let's say we were going to print out employees by department, and while we were doing that we were going to increase each employee's salary by 10% (because we're feeling generous today<g>) and then print out the new salary. Then the code (for hibernate) would look something like this:
Code:
public void editEmployeesHibernate() throws Exception {
Session session = sessionFactory.openSession();
lgr.info("starting edit");
Transaction t = session.beginTransaction();
Iterator deptIterator = session.iterate("from Department");
while (deptIterator.hasNext()) {
Department dept = (Department) deptIterator.next();
lgr.info(dept.getName());
Bag employees = dept.getEmployees();
Iterator empIterator = employees.iterator();
while (empIterator.hasNext()) {
Employee emp = (Employee) empIterator.next();
lgr.info("\t" + emp.getName() + " " + emp.getSalary());
emp.setSalary(emp.getSalary()*1.1f);
session.save(emp);
lgr.info("\t New Salary: " + emp.getSalary());
}
}
t.commit();
session.close();
lgr.info("ending edit");
}
This runs in 6 seconds. I would do a comparison JDBC, but I don't even want to think about what the JDBC code would look like to do the same thing... that's why I'm using Hibernate<g>.