2014-07-17 20 views
-3

我的数据库中有大约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')"), 
+0

我认为你需要重构你的关系。这么多联合既是令人难以置信的又是一个完全的性能杀手。 – Makoto

回答

0

您可以通过使用Hibernate的标准查询语言如下完成此任务: -

Crietria c=session.createCriteria(XYZ.class); 
c.setFirstResult(1); 
c.setMaxResult(500); 
相关问题