免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: cnhawk386
打印 上一主题 下一主题

欢迎访问** [复制链接]

论坛徽章:
0
1 [报告]
发表于 2006-06-08 10:24 |显示全部楼层

举个 获取对象(传递对象编码)的例子

/*********************************************************************************************
   *                      Function Name : 传递企业id获得该对象.
   *                       Return Value : PO
   *                            Creator : zhuwq
   *                        Create Time : 2006/02/28
   *                        Modify Time :
   **********************************************************************************************/

public GxCrmProjectPO getPOById(int id) throws
      HibernateException, Exception {
    Session s = this.beginTransaction();
    GxCrmProjectPO po = null;
    try {
      Query q = s.createQuery(
          "from GxCrmProjectPO as gcpo where gcpo.id=:id");
      q.setInteger("id", id);
      Iterator it = q.iterate();
      while (it.hasNext()) {
        po = (GxCrmProjectPO) it.next();
      }

      this.endTransaction(true);
    }
    catch (Exception ex) {
      System.out.println("GxCrmProjectBO.GxCrmProjectBO Method Failure: " +
                         ex.getMessage());
      this.endTransaction(false);
    }
    return po;

  }

论坛徽章:
0
2 [报告]
发表于 2006-06-08 11:16 |显示全部楼层
public class GxCrmProjectHetongBO
    extends AbsBaseMap {


}
AbsBaseMap是个抽象类,它中封装的所有的操作底层的接口.比如session,configure 等5大接口.
gcpo.id=:id 是HQL的语法规则.

论坛徽章:
0
3 [报告]
发表于 2006-06-08 11:53 |显示全部楼层
GxCrmProjectPO po =new GxCrmProjectPO ();
if(po = (GxCrmProjectPO) bo.findByIndentify(GxCrmProjectPO.class,
          new Integer(po.getId()))!=null){

bo.remove(po);
}
道理是一样的。
先查找,后删除。
Test t1=(Test)s1.get(Test.class,1);
s1.delete(t1);
你把1改称  new Integer(1) .
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP