我们可以使用命名查询来限制记录吗?

时间:2014-07-17 05:16:39

标签: java

我的数据库中有大约20000条记录,但我只想一次获取500条记录。我正在使用命名查询来获取数据。那么,我如何限制命名查询呢?

我试过这样,

@NamedQuery(name = "qryChildEventByOrganization", query = "select childEvent from ChildEvent childEvent  limit 500"
+ "left outer join fetch childEvent.child as ceChild "
+ "left outer join fetch ceChild.address as address "
+ "left outer join fetch ceChild.user as cuser "
+ "left outer join fetch childEvent.user as ceuser "
+ "left outer join fetch cuser.address as caddress "
+ "left outer join fetch ceuser.address as ceaddress "
+ "left outer join fetch ceChild.immunization as cimmunization "
+ "left outer join fetch ceChild.insurance as cinsurance "
+ "left outer join fetch ceChild.healthHistory as chealthHistory "
+ "left outer join fetch ceChild.emergencyContact as cemergencyContact "
+ "left outer join fetch ceChild.doctor as cdoctor "
+ "left outer join fetch ceChild.dietActivityRestriction as cdietActivityRestriction "
+ "left outer join fetch ceChild.allergy as cAllergy "
+ "left outer join fetch ceChild.medication as cMedication "
+ "left outer join fetch ceChild.provider as cProvider "
+ "left join fetch childEvent.event as ceEvent "
+ "left join fetch ceEvent.organization as eOrganization "
+ "left join fetch eOrganization.address as oAddress "
+ "left outer join fetch ceChild.childEvent as cChildEvent "
+ "left join fetch cChildEvent.event as ceEventChildCe "
+ "left join fetch ceEventChildCe.organization as eCeOrganization "
+ "left join fetch eCeOrganization.address as oCeAddress "
+ "left outer join fetch cChildEvent.child as cCEChild "
+ "left outer join fetch cCEChild.address as address "
+ "left outer join fetch cCEChild.user as cuser "
+ "left outer join fetch cuser.address as ceaddress "
+ "left outer join fetch cCEChild.immunization as cimmunization "
+ "left outer join fetch cCEChild.insurance as cinsurance "
+ "left outer join fetch cCEChild.healthHistory as chealthHistory "
+ "left outer join fetch cCEChild.emergencyContact as cemergencyContact "
+ "left outer join fetch cCEChild.doctor as cdoctor "
+ "left outer join fetch cCEChild.dietActivityRestriction as cdietActivityRestriction "
+ "left outer join fetch cCEChild.allergy as cAllergy "
+ "left outer join fetch cCEChild.medication as cMedication "
+ "where childEvent.event.organization.organizationId = :organizationId AND (childEvent.status is null OR childEvent.status LIKE 'Active')"),

1 个答案:

答案 0 :(得分:0)

您可以使用hibernate条件查询语言完成此任务,如下所示: -

Crietria c=session.createCriteria(XYZ.class);  
c.setFirstResult(1);  
c.setMaxResult(500);