zoukankan      html  css  js  c++  java
  • getHibernateTemplate() VS getSession()

    如题所示,对于这个问题,官网文档已给出答案,详见:

    /**
         * Obtain a Hibernate Session, either from the current transaction or
         * a new one. The latter is only allowed if the
         * {@link org.springframework.orm.hibernate3.HibernateTemplate#setAllowCreate "allowCreate"}
         * setting of this bean's {@link #setHibernateTemplate HibernateTemplate} is "true".
         * <p><b>Note that this is not meant to be invoked from HibernateTemplate code
         * but rather just in plain Hibernate code.</b> Either rely on a thread-bound
         * Session or use it in combination with {@link #releaseSession}.
         * <p>In general, it is recommended to use HibernateTemplate, either with
         * the provided convenience operations or with a custom HibernateCallback
         * that provides you with a Session to work on. HibernateTemplate will care
         * for all resource management and for proper exception conversion.
         * @return the Hibernate Session
         * @throws DataAccessResourceFailureException if the Session couldn't be created
         * @throws IllegalStateException if no thread-bound Session found and allowCreate=false
         * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession(SessionFactory, boolean)
         */
    org.springframework.orm.hibernate3.support.HibernateDaoSupport#getSession()

    Spring推荐我们使用HibernateTemplate,如有必要,则通过HibernateCallback来调用原生Session。

    推荐原因,HibernateTemplate可以帮助我们进行资源管理和适当的异常转换!

  • 相关阅读:
    weakself的另一种写法
    SDWebImage的使用说明
    关于AVPlayerItem对象的属性duration返回播放总时长的坑
    Xcode 问题
    循环引用问题
    使用Spring Animation的API创建动画
    iOS触摸事件处理
    OS开发中的事件处理(二)-事件传递,响应者链条
    python实现简单的百度云自动下载
    我眼中的K-近邻算法
  • 原文地址:https://www.cnblogs.com/kagome2014/p/6952778.html
Copyright © 2011-2022 走看看