以下是一个例子
==============================
package com.adasoft.sms.dao.hibernate;
import java.util.List;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class test extends HibernateDaoSupport{
/**
*
* @param insertList
* @return
*/
public boolean InsertEmployees(List insertList){
boolean result=true;
// SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
// Session session= sessionFactory.openSession();
Session session=SessionFactoryUtils.getSession(getSessionFactory(), true);
session.setFlushMode(FlushMode.COMMIT );
Transaction tx = null;
try {
tx = session.beginTransaction();
for(int i=0;i<insertList.size();i++){
//Employee employee=new Employee();
//employee=(Employee)insertList.get(i);
//this.saveEmployee(employee);
//.....
}
tx.commit();
}
catch (RuntimeException e) {
if (tx != null) tx.rollback();
result=false;
throw e; // or display error message
}
finally {
session.close();
}
return result;
}
}
分享到:
相关推荐
Hibernate3事务管理[借鉴].pdf
hibernate事务管理机制.dochibernate事务管理机制.doc
spring mvc hibernate 实现事务管理 jar包管理用maven,启动服务器用jetty,里边还有memcached数据库,但是本例子没有用到。
spring mvc hibernate整合,采用MyEclipse自动生成包和配置文件,jar包可能有多余,但是不影响整体效果。服务器tomcat。数据库mysql。
Hibernate的事务管理.doc
在Spring中配置Hibernate事务
spring3,hibernate4 配置声明式事务管理(annotation方式)
spring3hibernate4注解式事务管理
一个小实例工程,说的是spring3+hibernate4配置声明式事务管理(annotation方式)
hibernate事务管理hibernate事务管理
T21.12_Hibernate的事务管理 java 经典教程 经典教材
Spring将事务管理分成了两类: * 编程式事务管理 * 手动编写代码进行事务管理.(很少使用) * 声明式事务管理: * 基于TransactionProxyFactoryBean的方式.(很少使用) * 需要为每个进行事务管理的类,配置一个...
NULL 博文链接:https://microjava.iteye.com/blog/525981
Hibernate事务管理.很不错的哦!拿出来和大家一起来学习和分享哦!
hibernate 事务管理注意事项
通过实例你也许会明白hibernate事务,并发及缓存管理的运行原理,如果对这个感兴趣的可以看看
两个项目,一个项目是基于spring jdbc实现的分布式事务,一个是基于spring hibernate的分布式事务,hibernate项目里的applicationContext2.xml是基于mysql和mssql, applicationContext3.xml基于两个mssql, ...
spring3hibernate4注解是事务管理
spring3、 hibernate4 配置声明式事务管理(annotation方式)