最基本的HQL语句

public void queryByID(String id){

 

String hql="form Person where id=?";

Query q=this.session.createQuery(hql);

q.setString(0,id);

List list=q.list();

Iterator iter=list.iterator();

if(iter.hasNext()){

  p=(Person)iter.next();

 

}

return p;

 

 

public void delete(Person p){

 

  this.session.delete(p);

}

 

public void delete(String id){

  String hql="delect Person where id=?";

  Query q=this.session.createQuery(hql);

  q.setString(0,id);

  q.executeUpdate();

  this.session.beginTransaction().commit();

 

}

 

 

public List queryAll(){

  String hql="from Person p";

  Query q=this.session.createQuery(hql);

  List list=q.list();

  return list;

}

 

 

public list queryByLike(String cond){

  list l;

  Query q=this.session.createQuery("from person where name like ?");

  q.setString(0,"%+cond+%");

  l=q.list();

  

  return l;

}

你可能感兴趣的:(HQL)