锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产一区二区三区在线视频,蜜臀a∨国产成人精品,久久夜色精品http://www.aygfsteel.com/lonleung/category/45211.html 鎱墊噿鑰屾煍杞?/description>zh-cnFri, 04 Jun 2010 04:01:23 GMTFri, 04 Jun 2010 04:01:23 GMT60Hibernate DAO涓殑鍑犱釜鏂規硶http://www.aygfsteel.com/lonleung/archive/2010/06/04/322713.html鍑夋櫨鍑夋櫨Fri, 04 Jun 2010 03:53:00 GMThttp://www.aygfsteel.com/lonleung/archive/2010/06/04/322713.htmlhttp://www.aygfsteel.com/lonleung/comments/322713.htmlhttp://www.aygfsteel.com/lonleung/archive/2010/06/04/322713.html#Feedback0http://www.aygfsteel.com/lonleung/comments/commentRss/322713.htmlhttp://www.aygfsteel.com/lonleung/services/trackbacks/322713.html

* save()鏂規硶鎻愪緵浜嗗悜鏁版嵁搴撲腑娣誨姞鏁版嵁鐨勫姛鑳?浣嗗彧鑳芥坊鍔?榪欎釜DAO娌℃湁鐢熸垚Update()鐨勬柟娉?br /> * 浣嗕綘鍙互綆鍗曠殑鍏玸ave()鏂規硶鏀圭О鍏鋒湁Update鍔熻兘:灝唃etSession().save * (transientInstance);榪欏彞鏀規垚
* getSession().merge(transientInstance);鎴栬単etSession().saveOrUpdate
*  (transientInstance); 

public void save(User transientInstance) {
  log.debug("saving User instance");
  try {
   Session session=getSession();
   Transaction tx=session.beginTransaction();
   session.save(transientInstance);
   tx.commit();
   session.close();
   log.debug("save successful");
  } catch (RuntimeException re) {
   log.error("save failed", re);
   throw re;
  }
 }


delete()鏂規硶鐢ㄦ潵鍒犻櫎鐨?瀹為檯涓婃垜浠細鐢ㄤ笅杈圭殑榪欎釜鏂規硶榪涜鍒犻櫎

public void delete(Integer id){
  log.debug("deleting User instance…");
  User user=findById(id);
  delete(user);
 }
 
 public void delete(User persistentInstance) {
  log.debug("deleting User instance");
  try {
   Session session=getSession();
   Transaction tx=session.beginTransaction();
   session.delete(persistentInstance);
   tx.commit();
   session.close();
   log.debug("delete successful");
  } catch (RuntimeException re) {
   log.error("delete failed", re);
   throw re;
  }
 }

鏍規嵁緙栧彿榪涜鏌ユ壘

 public User findById(java.lang.Integer id) {
  log.debug("getting User instance with id: " + id);
  try {
   User instance = (User) getSession().get("hbm.User", id);
   return instance;
  } catch (RuntimeException re) {
   log.error("get failed", re);
   throw re;
  }
 }

findByExample()鏂規硶瀹炵幇鐨勫姛鑳界浉褰撲簬"select * from Usertable"瀹炵幇鐨勫姛鑳藉氨鏄煡璇㈡墍鏈?nbsp;鏁版嵁.

 public List findByExample(User instance) {
  log.debug("finding User instance by example");
  try {
   List results = getSession().createCriteria("hbm.User").add(
     Example.create(instance)).list();
   log.debug("find by example successful, result size: "
     + results.size());
   return results;
  } catch (RuntimeException re) {
   log.error("find by example failed", re);
   throw re;
  }
 }

findByProperty()鏂規硶鐢ㄦ潵鐏墊椿鐨勬彁渚涗竴縐嶆寜鏉′歡鏌ヨ鐨勬柟娉?浣犲彲浠ヨ嚜宸卞畾涔夎鎸変粈涔堟牱鐨勬柟 寮忔煡璇?

 public List findByProperty(String propertyName, Object value) {
  log.debug("finding User instance with property: " + propertyName
    + ", value: " + value);
  try {
   String queryString = "from User as model where model."
     + propertyName + "= ?";
   Query queryObject = getSession().createQuery(queryString);
   queryObject.setParameter(0, value);
   return queryObject.list();
  } catch (RuntimeException re) {
   log.error("find by property name failed", re);
   throw re;
  }
 }

 public List findByName(Object name) {
  return findByProperty(NAME, name);
 }

 public List findBySex(Object sex) {
  return findByProperty(SEX, sex);
 }

 public List findByAge(Object age) {
  return findByProperty(AGE, age);
 }

 public List findAll() {
  log.debug("finding all User instances");
  try {
   String queryString = "from User";
   Query queryObject = getSession().createQuery(queryString);
   return queryObject.list();
  } catch (RuntimeException re) {
   log.error("find all failed", re);
   throw re;
  }
 }

灝嗕紶鍏ョ殑detached鐘舵佺殑瀵硅薄鐨勫睘鎬у鍒跺埌鎸佷箙鍖栧璞′腑錛屽茍榪斿洖璇ユ寔涔呭寲瀵硅薄  濡傛灉璇ession涓病鏈夊叧鑱旂殑鎸佷箙鍖栧璞★紝鍔犺澆涓涓紝濡傛灉浼犲叆瀵硅薄鏈繚瀛橈紝淇濆瓨涓涓壇鏈茍浣滀負鎸佷箙瀵硅薄榪斿洖錛屼紶鍏ュ璞′緷鐒朵繚鎸乨etached鐘舵併?nbsp;

鍙互鐢ㄤ綔鏇存柊鏁版嵁

 public User merge(User detachedInstance) {
  log.debug("merging User instance");
  try {

    Session session=getSession();
   Transaction tx=session.beginTransaction();
   
   User result = (User) session.merge(detachedInstance);
   tx.commit();
   session.close();
   log.debug("merge successful");
   return result;
  } catch (RuntimeException re) {
   log.error("merge failed", re);
   throw re;
  }
 }

灝嗕紶鍏ョ殑瀵硅薄鎸佷箙鍖栧茍淇濆瓨銆?nbsp;濡傛灉瀵硅薄鏈繚瀛橈紙Transient鐘舵侊級錛岃皟鐢╯ave鏂規硶淇濆瓨銆傚鏋滃璞″凡淇濆瓨錛圖etached鐘舵侊級錛岃皟鐢╱pdate鏂規硶灝嗗璞′笌Session閲嶆柊鍏寵仈銆?/font>

 public void attachDirty(User instance) {
  log.debug("attaching dirty User instance");
  try {
   getSession().saveOrUpdate(instance);
   log.debug("attach successful");
  } catch (RuntimeException re) {
   log.error("attach failed", re);
   throw re;
  }
 }

灝嗕紶鍏ョ殑瀵硅薄鐘舵佽緗負Transient鐘舵?nbsp;

 public void attachClean(User instance) {
  log.debug("attaching clean User instance");
  try {
   getSession().lock(instance, LockMode.NONE);
   log.debug("attach successful");
  } catch (RuntimeException re) {
   log.error("attach failed", re);
   throw re;
  }
 }



鍑夋櫨 2010-06-04 11:53 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 沙田区| 林甸县| 印江| 东至县| 望都县| 尉犁县| 随州市| 东阳市| 福海县| 剑阁县| 平和县| 宜城市| 拉孜县| 油尖旺区| 清徐县| 正阳县| 新郑市| 石阡县| 仁怀市| 锦屏县| 元阳县| 鄂州市| 东辽县| 河北区| 麻江县| 黎川县| 九龙城区| 岳阳县| 翁牛特旗| 揭西县| 肇源县| 梁河县| 本溪市| 丰顺县| 大姚县| 崇文区| 阳高县| 乌拉特中旗| 华容县| 苍梧县| 梧州市|