Pergunta

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);
    }

}
Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top