想看看hibernate托管给spring的 是怎么回事,看后再发现也是ioc注入
只是个人理解 可能有误,还请牛人拍砖
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;
// set注入sessionFactory
public final void setSessionFactory(SessionFactory paramSessionFactory)
{
this.hibernateTemplate = createHibernateTemplate(paramSessionFactory);
}
//创建HibernateTemplate 俺们就是用这个对象
protected HibernateTemplate createHibernateTemplate(SessionFactory paramSessionFactory)
{
return new HibernateTemplate(paramSessionFactory);
}
public final SessionFactory getSessionFactory()
{
return ((this.hibernateTemplate != null) ? this.hibernateTemplate.getSessionFactory() : null);
}
public final void setHibernateTemplate(HibernateTemplate paramHibernateTemplate)
{
this.hibernateTemplate = paramHibernateTemplate;
}
public final HibernateTemplate getHibernateTemplate()
{
return this.hibernateTemplate;
}
protected final void checkDaoConfig() {
if (this.hibernateTemplate == null)
throw new IllegalArgumentException("'sessionFactory' or 'hibernateTemplate' is required");
}
//创建session
protected final Session getSession()
throws DataAccessResourceFailureException, IllegalStateException
{
return getSession(this.hibernateTemplate.isAllowCreate());
}
protected final Session getSession(boolean paramBoolean)
throws DataAccessResourceFailureException, IllegalStateException
{
return ((!(paramBoolean)) ? SessionFactoryUtils.getSession(getSessionFactory(), false) : SessionFactoryUtils.getSession(getSessionFactory(), this.hibernateTemplate.getEntityInterceptor(), this.hibernateTemplate.getJdbcExceptionTranslator()));
}
protected final DataAccessException convertHibernateAccessException(HibernateException paramHibernateException)
{
return this.hibernateTemplate.convertHibernateAccessException(paramHibernateException);
}
protected final void releaseSession(Session paramSession)
{
SessionFactoryUtils.releaseSession(paramSession, getSessionFactory());
}
分享到:
相关推荐
Spring hibernate3. HibernateDaoSupport 源码
HibernateDaoSupport详解 HibernateDaoSupport详解
HibernateDaoSupport的使用
hibernateDaoSupport类的详解!
NULL 博文链接:https://yizhilong28.iteye.com/blog/818989
SSH整合(其中dao用extends HibernateDaoSupport方式)总结【图解】
HibernateDaoSupport 类的jar HibernateDao 的jar
springboot2.0多数据源集成hibernate配置hibernateDaoSupport, dao层继承hibernateDaoSupport, 不使用jpa方式。
.相同点:在applicationConext.xml中 ... HibernateDaoSupport: 在impl中要调用的方法要getHibernateTemplate().delete(user); UserDaoHiberateImpl: 在impl中要调用的方法要hibernateTemplate.save(user);
HibernateDaoSupport分页.txt
hibernateTemplate和HibernateDaoSupport
HibernateDaoSupport与JdbcDaoSupport总结
HibernateDaoSupport方法的解释,比较详细,对初学者很有帮助
java基于SSH框架的学生成绩管理系统源码。要求: (1) 整合Struts2、Spring和Hibernate框架 (2) 实现“登录”功能 (3) 实现“学生信息管理”功能 (4) 实现“学生成绩管理”功能 (5) 实现分页功能 目的...
弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件。本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mvc和rest小例子没有介绍到数据层的内容,...
HibernateDaoSupport二次封装组件,快速统计和查询,修改,删除,并且对SQL语句的in,or,exitsts都有涉及
NULL 博文链接:https://godit.iteye.com/blog/1716651
编写DAO的时候尽量不直接使用hibernate或者spring对hiberanate的支持
NULL 博文链接:https://wxinpeng.iteye.com/blog/1162157
spring-boot 集成hibernate,使用druid数据库连接池,dao继承HibernateDaoSupport 的实现,