Reputation: 9
I am using Struts and Spring jdbc template right in my application.
I have to use Hibernate template in our code.
Can any one tell me why should I use Hibernate template?
And what is problem using Spring jdbc template?
Upvotes: 0
Views: 3107
Reputation: 667
There are two issues:
JdbcTemplate is useful for calling simple DAOs that don't fit a domain model or just small amounts of data access period. Its also useful if you have a couple of stored procedures. If you have a lot of stored procedures, iBatis is better (which Spring also integrates with)
Hibernate requires some form of mapping specified in XML or annotations. But once you get beyond a few DAOs with only a couple of methods, Hibernate has the power to uniformly manage Object to relational mappings.
This class can be considered as direct alternative to working with the raw Hibernate3 Session API (through SessionFactory.getCurrentSession()). The major advantage is its automatic conversion to DataAccessExceptions as well as its capability to fall back to 'auto-commit' style behavior when used outside of transactions.
So unless you are planning mixing JDBC with Hibernate or you just happen to prefer Spring's DataAccessException hierarchy HibernateTemplate would be a good solution. But if you don't have a specific reason to use HibernateTemplate, straight Hibernate (even when using Spring TransactionProxyFactoryBean) is the way to go.
Upvotes: 3
Reputation: 17903
Using Spring Template (JDBC, Hibernate) saves a lot effort on clean up, resource management and better exception handling. Checkout the following these link
http://www.vogella.de/articles/SpringJDBC/article.html
Upvotes: 2