I am confused b/w these two both are used for same purpose apart from this hibernatetemplate is from orm package and Jdbctemplate is from jdbc package. I want to know when we have HibernateTemplate then why we need JdbcTemplate or vise versa. And when to use one of them and which is more better to use.
-
possible duplicate of [differences between spring jdbctemplate and Hibernate](http://stackoverflow.com/questions/17301122/differences-between-spring-jdbctemplate-and-hibernate) – Bhavik Ambani Jan 01 '14 at 08:54
-
Refer this Question http://stackoverflow.com/questions/11791145/spring-jdbctemplate-vs-hibernate-in-terms-of-performance – Sankar Ganesh PMP Jan 01 '14 at 08:57
-
1@Bhavik Ambani: the question reffered by you explain the difference between SpringJdbcTemplate and Hibernate, but not between SpringJdbcTemplate and HibernateTemplate – Ralph Jan 01 '14 at 09:12
-
Are you really confused about it?! Do you really think they do the same thing? Have you seen their methods signatures? – Amir Pashazadeh Jan 01 '14 at 09:25
2 Answers
If you have a normalized database where you can easily map tables to Java classes that represent business entities, then you may do well with HibernateTemplate (And even better with Spring JPA Repositories).
If you have a legacy database that is not normalized and mapping tables to business entities is a hard work, you'll have to use JdbcTemplate

- 10,561
- 4
- 45
- 63
HibernateTemplate v/s JdbcTemplate
Both HibernateTemplate and JdbcTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked exceptions into unchecked DataAccessExceptions.
Spring provides support for both hibernate and JDBC template classes. It provides template classes which contains all common code. But JDBC as we all know is not an ORM tool it does not represent rows as objects whereas Hibernate does that.
If you are using hibernate in your project then recommend to use HibernateTemplate and if you are not using hibernate then recommend to use JdbcTemplate class.

- 19
- 2