`
holdbelief
  • 浏览: 706110 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Implementing Spring-based DAOs without callbacks

阅读更多

~



 

附上源码更清楚(部分):

package org.springframework.orm.hibernate3.support;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.support.DaoSupport;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.SessionFactoryUtils;


public abstract class HibernateDaoSupport extends DaoSupport {

 private HibernateTemplate hibernateTemplate;

……

 /**
  * 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)
  */
 protected final Session getSession()
     throws DataAccessResourceFailureException, IllegalStateException {

  return getSession(this.hibernateTemplate.isAllowCreate());
 }

 /**
  * Obtain a Hibernate Session, either from the current transaction or
  * a new one. The latter is only allowed if "allowCreate" 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
  * {@link #getHibernateTemplate() HibernateTemplate}, either with
  * the provided convenience operations or with a custom
  * {@link org.springframework.orm.hibernate3.HibernateCallback} that
  * provides you with a Session to work on. HibernateTemplate will care
  * for all resource management and for proper exception conversion.
  * @param allowCreate if a non-transactional Session should be created when no
  * transactional Session can be found for the current thread
  * @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)
  */
 protected final Session getSession(boolean allowCreate)
     throws DataAccessResourceFailureException, IllegalStateException {

  return (!allowCreate ?
      SessionFactoryUtils.getSession(getSessionFactory(), false) :
    SessionFactoryUtils.getSession(
      getSessionFactory(),
      this.hibernateTemplate.getEntityInterceptor(),
      this.hibernateTemplate.getJdbcExceptionTranslator()));
 }

……
}

 

而 HibernateTemplate 中,allowCreate 的默认值是 true,抄录部分源码如下:
public class HibernateTemplate extends HibernateAccessor implements HibernateOperations {

 private boolean allowCreate = true;

 …… 

}

  • 大小: 100.5 KB
分享到:
评论

相关推荐

    Implementing Domain-Driven Design epub

    Implementing Domain-Driven Design 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    spring-boot-reference.pdf

    13.2.2. Using Spring Boot without the Parent POM 13.2.3. Using the Spring Boot Maven Plugin 13.3. Gradle 13.4. Ant 13.5. Starters 14. Structuring Your Code 14.1. Using the “default” Package 14.2. ...

    Implementing Domain-Specific Languages with Xtext and Xtend(PACKT,2013)

    Xtext is an open source Eclipse framework for implementing domain-specific languages together with its IDE functionalities. It lets you implement languages really quickly, and, most of all, it covers ...

    Implementing Domain-Driven Design

    Implementing Domain-Driven Design

    hands-full-stack-development-spring-boot-2-react

    the technical design, and all the way to implementing, testing, production, deployment, and monitoring. This book covers the full set of technologies that you need to know to become a full-stack web ...

    Edge Based Template Matching.pdf

    原文链接https://www.codeproject.com/Articles/99457/Edge-Based-Template-Matching; 其中vs2015+opencv3.3版code:https://download.csdn.net/download/zfjbit/10732568

    Implementing Domain Driven Design

    With Implementing Domain-Driven Design, Vaughn has made an important contribution not only to the literature of the Domain-Driven Design community, but also to the literature of the broader enterprise...

    Implementing CIFS - pdf

    《Implementing CIFS》这本书是关于实施Common Internet File System (CIFS)协议的权威指南,CIFS是一种广泛使用的网络文件共享协议,特别是在Windows环境中。该书深入探讨了CIFS的各个方面,包括其工作原理、配置、...

    The Craft of Model-Based Testing

    The Craft of Model-Based Testing by Paul C. Jorgensen English | 2017 | ISBN: 1498712282 | 456 pages | PDF | 10,7 MB In his latest work, author Paul C Jorgensen takes his well-honed craftsman’s ...

    Microcontroller Based Temperature Monitoring and Control

    *Includes real-world design guides for implementing a microcontroller-based control systems *Requires only basic mathematical and engineering background as the use of microcontrollers is introduced ...

    Implementing CIFS - The Common Internet File System

    文档《Implementing CIFS - The Common Internet File System》详细介绍了CIFS协议的概念、架构以及实施方法。该文档以非印刷版的形式呈现,由多个分片的PDF文件组成一个完整的文档,提供了对CIFS/SMB协议的全面分析...

    spring-framework-reference-4.1.2

    Composing XML-based configuration metadata .......................................... 25 Using the container .......................................................................................... ...

    FPGA.Design.Best.Practices.for.Team-based.Reuse.33191792

    By gaining an understanding into their design environments, processes, what works and what does not work, key areas of concern in implementing system designs have been identified and a recommended ...

    Implementing Deutsch-Jozsa algorithm using superconducting qubit network

    基于超导量子比特网络的Deutsch-Jozsa算法实现方案,郑小虎,Ming Yang,提出了一个通过电流偏置实现普适逻辑门的改进结构,此改进对实现可扩展的功能强大的量子计算机是必不可少的,目前的技术能制造此

    spring-framework-reference4.1.4

    Composing XML-based configuration metadata .......................................... 25 Using the container .......................................................................................... ...

Global site tag (gtag.js) - Google Analytics