I have a project with Spring 4 and Hibernate 4 as JPA. And I have a DAO-layer bean with method like:
@Transactional
public MyDtoObject getDataWithALotAggregation(String params){
String queryStr = "select aLotAggregatedData from aLotJoinedTables where aLotParams="+params;
Object[] rawData = sessionFactory
.getCurrentSession()
.createSQLQuery(queryStr)
.uniqueResult();
return mapRawDataToMyDtoObject(rawData);
}
and I just compared timing of this method with timing of jdbcTemplate.queryForObject(queryStr, mapper, params)
and
I got surprised that Hibernate is bit faster than JDBC API (~5-10%).
Any idea why Hibernate is faster or JdbcTemplate so slow?
I was sure that Hibernate especially with transactions should be slower than JdbcTemplate...