2014-07-17 2 views
-3

DB에 약 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

당신은 다음과 같이 최대 절전 모드 기준 쿼리 언어를 사용하여이 작업을 얻을 수 있습니다 -

Crietria c=session.createCriteria(XYZ.class); 
c.setFirstResult(1); 
c.setMaxResult(500); 
관련 문제