Spring自己控制事务
applicationContext.xml
<bean id="userInfoDao" name="code">public class TestOgi1DaoImpl extends HibernateDaoSupport implements TestOgi1Dao{ public boolean save(TestOgi1 transientInstance) { log.debug("saving TestOgi1 instance"); Session session = null; Transaction tx = null; try { // System.out.println(this.getHibernateTemplate().getSessionFactory().getCurrentSession()); // getHibernateTemplate().merge(transientInstance); session = this.getSession(true); tx = session.beginTransaction(); session.save(transientInstance); tx.commit(); log.debug("save successful"); return true; } catch (RuntimeException re) { log.error("save failed", re); tx.rollback(); throw re; } finally { if (session.isOpen()) { session.close(); } } } public List findByProperty(String propertyName, Object value) { log.debug("finding TestOgi1 instance with property: " + propertyName + ", value: " + value); try { String queryString = "from TestOgi1 as model where model." + propertyName + "= ?"; return getHibernateTemplate().find(queryString, value); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } } }