【问题标题】:org.springframework.orm.hibernate3.HibernateTemplateorg.springframework.orm.hibernate3.HibernateTemplate
【发布时间】:2014-03-29 23:26:39
【问题描述】:

我们通过使用以下包来使用休眠模板。

org.springframework.orm.hibernate3.HibernateTemplate;

protected HibernateTemplate template = null;

这里的模板来自org.springframework.orm.hibernate3.HibernateTemplate 包。我无法理解如何解释这个包。

它是spring hibernate吗,因为包名以springframework开头。但是没有这样的spring hibernate。我猜春天只有 ORM 模块。

谁能帮我理解如何理解这个包org.springframework.orm.hibernate3.HibernateTemplate.

更新: 下面是我正在使用的确切存储库类

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

}

【问题讨论】:

    标签: spring hibernate spring-orm


    【解决方案1】:

    Spring以HibernateTemplate的形式提供了与Hibernate 3和4的集成,你展示的提供了与Hibernate 3的集成。

    该类的主要目标是通过回调提供 Hibernate 会话,另一个重要功能是将 Hibernate 异常转换为 Spring 异常。

    不再推荐使用这个类,看看这个answer。推荐的方式是使用@Transactional注解。

    【讨论】:

    • 更新我的帖子,我是如何使用它的。你的意思是,我们不需要使用hibernatetemplate,而是可以直接使用Session session = sessionFactory.getCurrentSession()?
    • 是的,它是正确的,请参阅此答案stackoverflow.com/questions/4699381/…
    猜你喜欢
    • 2011-06-19
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 2018-05-30
    • 2012-06-02
    相关资源
    最近更新 更多