Hello.
This difference appears on executing querys directly on database, getting the connection from a hibernate session. It takes 606 milliseconds in average to run every query through hibernate's connection. While running the same querys creating a new connection (without hibernate), the execution time is 4 milliseconds in average.
Below is the code used to run the querys.
There are about 7000 querys, what takes about 1:10 hour to run with hibernate, against 32.4 seconds without it.
Code:
Transaction tx=null;
try{
tx = session.beginTransaction();
Connection con = session.connection();
con.setAutoCommit(false);
Statement stmt = con.createStatement();
for (Iterator iter = dtos.iterator(); iter.hasNext();) {
IntegracaoEstabDTO dto = (IntegracaoEstabDTO) iter.next();
stmt.addBatch("update Estabelecimento set totalAlunos = " + dto.getTotalAlunos() + " where municipio.codigo = " + dto.getCodigoMunicipio() + " and codigoEstabelecimento = " + dto.getCodigoEstabelecimento());
}
stmt.executeBatch();
con.commit();
stmt.close();
session.flush();
tx.commit();
con.setAutoCommit(true);
}
catch(HibernateException he){ .....
Is something wrong with my code?
Or that performance is normal for querys with hibernate, what makes its use prohibitive?
Thanks in advice!
Danilo Kovalechyn.
Hibernate version:2.1.6
Name and version of the database you are using: PostgreSQL 7.4.1