• 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可以帮助我们进行资源管理和适当的异常转换!

  • 相关阅读:
    echars柱状图修改每条柱的颜色
    vue打开到新页面,并传递参数
    彻底了解websocket原理
    bind和on的区别
    Vue如何更新子组件
    Vue父子组件生命过程
    使用css3实现动画来开启GPU加速
    前端技术体系
    Vue中的~(静态资源处理)
    垂直居中的办法小结
  • 原文地址:https://www.cnblogs.com/kagome2014/p/6952778.html
Copyright © 2020-2023  润新知