1

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...

Ivan Zelenskyy
  • 659
  • 9
  • 26

1 Answers1

1

The reason why it is slower most likely because query generated by hibernate is different than yours.

My guess is that your code has this .uniqueResult();, which checks for duplicate objects. The bigger the dataset is, the more you will feel it in your case. However, it might be the number of columns mapped. The more columns are requested, the slower the response is.

Alan Sereb
  • 2,358
  • 2
  • 17
  • 31