hibernate 查询

/**
* 删除
* @param pid
* @return
*/
public boolean remove(String[] pid) {
String hql="DELETE FROM PFamilyinfo WHERE pid in (:pid)";
Query q = this.getSession().createQuery(hql);
q.setParameterList("pid",Arrays.asList(pid));
int count= q.executeUpdate();
return count>0;
}

hql=" select {t.*}  from p_credittype t where t.schoolid=?  " +
" start with t.id in " +
"(select t.id from p_credittype t where t.fatherid=0) " +
" connect by prior t.id=t.fatherid";

               
    Query q = this.getSession().createSQLQuery(hql)
    .addEntity("t", PCredittype.class);
   
q.setLong(0, new Long(sId) );
q.setFirstResult( (currentPage-1)*pageSize );
q.setMaxResults(pageSize);
List list = q.list();


List results = null;
   results = this.getSession().createCriteria(PCredittype.class)
.add(Restrictions.eq("schoolid", sid))
.add(Restrictions.eq("typerank", typerank))
.add(Restrictions.eq("flag", new Long(flag)))
.addOrder(Order.asc("id"))
.list();


StringBuilder sb = new StringBuilder();
sb.append(" select id,email,tel,fax,website,city,address,companynature,companyscale,companyname,contact,postcode,companydesc from ");
sb.append(" e_company ");
sb.append(" where id = ? ");

Long lcompanyid = Long.valueOf(companyid);
Long lcollegeid = Long.valueOf(collegeid);

List list =  this.getListBySQL(sb.toString(), -1, ECompanyPojo.class, lcompanyid);
if(list==null || list.isEmpty()){
return null;
}
else{
return (ECompanyPojo)list.get(0);
}

List list=null;
list=this.getSession(true).createCriteria(TSchoolId.class)
   .add(Restrictions.eq("fatherid", sid))
   .add(Restrictions.eq("schoolrank", scrank))
   .addOrder(Order.desc("flag"))
   .setFirstResult((currentPage-1)*pageSize)
   .setMaxResults(pageSize)
   .list();
return list;


public PFamilyinfo getFamilyinfo(Long pid) {

PFamilyinfo pfi  =(PFamilyinfo)  this.getSession().createCriteria(PFamilyinfo.class)
        .add(Restrictions.eq("pid", pid))
.uniqueResult();

return pfi;
}

/**
* 检查学生有没有家庭信息
* @param id
* @return
*/
public boolean isExistbyId( Long id){
int count =(Integer)this.getSession().createCriteria(PFamilyinfo.class)
.setProjection(Projections.rowCount())
.add(Restrictions.eq("id", id))
.uniqueResult();
return count>0;

}
/**
* 检查学生有没有家庭信息
* @param pid
* @return
*/
public boolean isExistbyPid(Long pid){
int count =(Integer)this.getSession().createCriteria(PFamilyinfo.class)
.setProjection(Projections.rowCount())
.add(Restrictions.eq("pid", pid))
.uniqueResult();
return count>0;

}

你可能感兴趣的:(Hibernate)