Dao层代码:
public Serializable add(Object entity) {
return this.getHibernateTemplate().save(entity);
}
不管什么异常,只要你catch了,spring就会放弃经管。
Session session = this.getHibernateTemplate().getSessionFactory().openSession()/buildSession()/getCurrentSession();
Transaction tx = session.beginTransaction();
tx.begin();
try {
for (Object o : entity){
session.save(o);
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}
session.close();
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</context-param>
本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/archive/2013/02/26/2933101.html,如需转载请自行联系原作者