1

We are using hibernate template by using the following package.

org.springframework.orm.hibernate3.HibernateTemplate;

protected HibernateTemplate template = null;

here template is from org.springframework.orm.hibernate3.HibernateTemplate package. I am not able to understand how to interpret this package.

is it the spring hibernate because package name starts with springframework. But there is no such spring hibernate. There is only ORM module i guess in spring.

Can anyone help me understand how to understand this package org.springframework.orm.hibernate3.HibernateTemplate.

update: below is the exactly repository class I am using

@Repository
@Transactional
public class ABCDImplements ABCD {

private Log logger = LogFactory.getLog(this.getClass());

    protected HibernateTemplate template = null;

    @Resource(name = "abcSessionFactory")
    protected SessionFactory sessionFactory;

    @Autowired
    public void init(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        template = new HibernateTemplate(sessionFactory);
    }

}
user3448119
  • 107
  • 10

1 Answers1

1

Spring provides integration with Hibernate 3 and 4 under the form of HibernateTemplate, and the one you show provides integration with Hibernate 3.

The main goal of this class was to provide a Hibernate session via a callback, and another important functionality was to translate Hibernate exceptions to Spring exceptions.

The use of this class is not recommended anymore, have a look at this answer. The recommended way is to use the @Transactional annotation.

Community
  • 1
  • 1
Angular University
  • 42,341
  • 15
  • 74
  • 81
  • update my post,how I am exactly using it. you mean, we don't need to use the hibernatetemplate rather we can directly use Session session = sessionFactory.getCurrentSession() ? – user3448119 Mar 30 '14 at 00:24
  • yes that it correct, see this answer as well http://stackoverflow.com/questions/4699381/best-way-to-inject-hibernate-session-by-spring-3 – Angular University Mar 30 '14 at 00:29