gavin wrote:
1) You should *always* do benchmarks in a loop, esp. in a hotspot JVM
2) Your test is also measuring the time taken to obtain a JDBC connection and start a transaction (note that the connection is first obtained during this find() call)
If your tests were implemented sensibly, there is no measurable difference between the performance of find(), and the direct JDBC.
Thank you,
But i use DCP. If i pass the connection in the session the result is equivalent.
The test executes one find method, one iterate method and find method twice again:
static void findPersonne() throws Exception {
Session session = null;
try {
Connection con = getConnection();
long start = System.currentTimeMillis();
session = sf.openSession(con);
String query = "from test.IPersonne personne where personne.nom like :name";
List result = session.find(query, "THIR%", Hibernate.STRING);
for (Iterator iter = result.iterator(); iter.hasNext();) {
Object o = iter.next();
//System.out.println(o instanceof PersonnePhysique);
}
System.out.println("find executed: " + (System.currentTimeMillis() - start));
} finally {
try {
session.close().close();
} catch (HibernateException he) {
System.out.println("HibernateException " + he.getMessage());
}
}
}
The main method:
public static void main(String[] args) throws Exception {
Configuration cfg = null;
Properties props = new Properties();
try {
cfg = new Configuration()
.addClass(Personne.class)
.addProperties(props);
sf = cfg.buildSessionFactory();
} catch (HibernateException he) {
System.out.println("HibernateException " + he.getMessage());
}
findPersonne();
iteratePersonne();
findPersonne();
findPersonne();
}
Thanks