首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Spring自个儿控制事务

2012-06-28 
Spring自己控制事务applicationContext.xmlbean iduserInfoDao namecodepublic class TestOgi1Dao

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;          }      }  }

热点排行