HQL的增删改查操作

实体更新
Transaction trans=session.beginTransaction();   
String hql=”update User user set user.age=20 where user.age=18”;   
Query queryupdate=session.createQuery(hql);   
int ret=queryupdate.executeUpdate();   
trans.commit();
实体删除
Transaction trans=session.beginTransaction();   
String hql=”delete from User user where user.age=18”;   
Query queryupdate=session.createQuery(hql);   
int ret=queryupdate.executeUpdate();   
trans.commit();
属性查询
List list=session.createQuery(“select user.name from User user ”).list();   
for(int i=0){   System.out.println(list.get(i));   }

一次检索多个属性,如下面程序:   
List list=session.createQuery(“select user.name,user.age from User user ”).list();   for(int i=0;i<list.length();i++){   Object[] obj=(Object[])list.get(i);   System.out.println(obj[0]);   System.out.println(obj[1]);   }
posted @ 2011-11-22 09:24  chenchun  阅读(8143)  评论(0编辑  收藏  举报