关闭

关闭

关闭

封号提示

内容

首页 HQL与Criteria对照.pdf

HQL与Criteria对照.pdf

HQL与Criteria对照.pdf

上传者: gaotmgaotm 2012-04-11 评分 0 0 0 0 0 0 暂无简介 简介 举报

简介:本文档为《HQL与Criteria对照pdf》,可适用于IT/计算机领域,主题内容包含HQLCriteria查询所有Stringhql="fromEmployee"List<Employee>result=(List<Employee符等。

HQLCriteria查询所有Stringhql="fromEmployee"List<Employee>result=(List<Employee>)sessioncreateQuery(hql)list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)list()条件过滤=、!=>、>=<、<=Stringhql="fromEmployeeewhereeage=:age"List<Employee>result=(List<Employee>)sessioncreateQuery(hql)setInteger("age",age)list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)add(Restrictionseq("age",age))add(Restrictionsne("age",age))add(Restrictionsgt("age",age))add(Restrictionsge("age",age))add(Restrictionslt("age",age))add(Restrictionsle("age",age))list()条件过滤betweenandStringhql="fromEmployeeewhereeagebetween:fromAgeand:toAge"List<Employee>result=(List<Employee>)sessioncreateQuery(hql)setInteger("fromAge",fromAge)setInteger("toAge",toAge)list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)add(Restrictionsbetween("age",fromAge,toAge))list()条件过滤isStringhql="fromEmployeeewhereedepartmentis"Stringhql="fromEmployeeewhereedepartmentisnot"List<Employee>result=List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)add(Restrictionsis("department"))add(RestrictionsisNot("department"))list()(List<Employee>)sessioncreateQuery(hql)list()条件过滤集合属性sizeStringhql="fromDepartmentdwheredemployeesisempty"Stringhql="fromDepartmentdwheredemployeesisnotempty"Stringhql="fromDepartmentdwheredemployeessize>"Stringhql="fromDepartmentdwheredemployeessize<"List<Department>result=(List<Department>)sessioncreateQuery(hql)list()List<Department>result=(List<Department>)sessioncreateCriteria(Departmentclass)add(RestrictionsisEmpty("employees"))add(RestrictionsisNotEmpty("employees"))add(RestrictionssizeGt("employees",))add(RestrictionssizeLt("employees",))list()条件过滤通配符Stringhql="fromEmployeeewhereenamelike:name"List<Employee>result=(List<Employee>)sessioncreateQuery(hql)setString("name",name"")list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)add(Restrictionslike("name",name""))add(Restrictionslike("name",name,MatchModeSTART))list()条件过滤多条件Stringhql="fromEmployeeewhere(edepartmentisnotandeage>)oreage<"List<Employee>result=(List<Employee>)sessioncreateQuery(hql)list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)add(Restrictionsor(Restrictionsand(RestrictionsisNot("department"),Restrictionsgt("age",)),Restrictionslt("age",)))list()条件过滤inStringhql="fromEmployeeewhereeidin(,,)"List<Employee>result=(List<Employee>)sessioncreateQuery(hql)list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)add(Restrictionsin("id",newInteger{,,}))list()排序Stringhql="fromEmployeeeorderbyeage"Stringhql="fromEmployeeeorderbyeagedesc"sessioncreateCriteria(Employeeclass)addOrder(Orderasc("age"))addOrder(Orderdesc("age"))投影select列Stringhql="selectenamefromEmployeee"Queryquery=sessioncreateQuery(hql)List<Object>result=(List<Object>)querylist()List<Object>result=(List<Object>)sessioncreateCriteria(Employeeclass)setProjection(Projectionsproperty("name"))list()投影select多列Stringhql="selectename,eagefromEmployeee"Queryquery=sessioncreateQuery(hql)List<Object>result=(List<Object>)querylist()List<Object>result=(List<Object>)sessioncreateCriteria(Employeeclass)setProjection(ProjectionsprojectionList()add(Projectionsproperty("name"))add(Projectionsproperty("age")))list()聚集CountMaxMinStringhql="selectcount(age),max(age),min(age),avg(age),sum(age)fromEmployee"Objectresult=Objectresult=(Object)sessioncreateCriteria(Employeeclass)setProjection(ProjectionsprojectionList()add(ProjectionsrowCount())AvgSum(Object)sessioncreateQuery(hql)uniqueResult()add(Projectionsmax("age"))add(Projectionsmin("age"))add(Projectionsavg("age"))add(Projectionssum("age")))uniqueResult()投影ResultTransferStringhql="selectnewcomjeffvoStatInfo(count(eid),max(eage),min(eage),avg(eage))fromEmployeee"Queryquery=sessioncreateQuery(hql)List<StatInfo>result=(List<StatInfo>)querylist()List<StatInfo>result=(List<StatInfo>)sessioncreateCriteria(Employeeclass)setProjection(ProjectionsprojectionList()add(Projectionscount("id")as("count"))add(Projectionsmax("age")as("maxAge"))add(Projectionsmin("age")as("minAge"))add(Projectionsavg("age")as("avgAge")))setResultTransformer(TransformersaliasToBean(StatInfoclass))list()分组GroupbyStringhql="selectedepartmentname,count(age),max(age),min(age),avg(age),sum(age)fromEmployeeegroupbyedepartment"List<Object>result=(List<Object>)sessioncreateQuery(hql)list()List<Object>result=(List<Object>)sessioncreateCriteria(Employeeclass)setProjection(ProjectionsprojectionList()add(Projectionsproperty("department"))add(ProjectionsrowCount())add(Projectionsmax("age"))add(Projectionsmin("age"))add(Projectionsavg("age"))add(Projectionssum("age"))add(ProjectionsgroupProperty("department")))list()联结JoinStringhql="fromEmployeeewhereedepartmentid="隐式联结Stringhql="selectefromEmployeeejoinedepartmentdwheredid="显式联结Queryquery=sessioncreateQuery(hql)List<Employee>result=(List<Employee>)querylist()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)createCriteria是Session的方法add(Restrictionsgt("age",))createCriteria("department")createCriteria是Criteria的方法add(Restrictionseq("id",))list()List<Employee>result=(List<Employee>)sessioncreateCriteria(Employeeclass)createAlias("department","d")add(Restrictionsgt("age",))add(Restrictionseq("did",))list()动态抓取FetchStringhql="fromDepartmentdleftjoinfetchdemployeeswheredid="Queryquery=sessioncreateQuery(hql)department=(Department)queryuniqueResult()department=(Department)sessioncreateCriteria(Departmentclass)setFetchMode("employees",FetchModeJOIN)add(Restrictionseq("id",))uniqueResult()命名查询NamedQueryquery=sessiongetNamedQuery("getByAge")gaotianming波浪线QueryQueryquery=sessiongetNamedQuery("comjeffmodelEmployeegetByAge")querysetInteger("ageParam",)List<Employee>result=(List<Employee>)querylist()离线查询DetachedCriteriaDetachedCriteriacond=DetachedCriteriaforClass(Employeeclass)add(Restrictionseq("age",))List<Employee>result=condgetExecutableCriteria(session)list()gaotianming高亮gaotianming高亮

用户评论(0)

0/200

精彩专题

上传我的资料

每篇奖励 +2积分

资料评价:

/6
0下载券 下载 加入VIP, 送下载券

意见
反馈

立即扫码关注

爱问共享资料微信公众号

返回
顶部