-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Need Equivalent Hibernate Query for the SQL Query.
PostPosted: Tue Sep 16, 2008 3:00 am 
Newbie

Joined: Tue Aug 26, 2008 3:13 am
Posts: 1
I need a equivalent hibernate criteria for this sql query. Thanks in advance.

Code:
select p.personId_pk as 'Patient ID',concat(p.lastname,' ',p.middlename,' ',p.firstname) as 'Patient Name',
       h.name as 'Health Care Facility Name',concat(pr.lastname,' ',pr.middlename,' ',pr.firstname) as 'Practitioner Name',
       sa.occuranceDateTime as 'Date & Time',nc.shortDescription as 'System Notifications'
from person p, person pr,healthCareProvider h,healthCareProviderStaff ph,patientPractitionerHealthcareProvider pph,personrole pl,personContact pc,systemAlertInfo sa,notificationConfig nc,patienthealthcareprovider phcp
  where (pph.healthCareProviderStaff_fk = ph.healthCareProviderStaff_pk and ph.personid_fk = pr.personid_pk and pl.roletype_fk = 2)
       and pph.patientid_fk = p.personid_pk and (phcp.statusCode = 'A' and phcp.patientId_fk = p.personId_pk)
       and h.healthCareProvider_pk = ph.healthCareProvider_fk and p.personId_pk = pc.personId_fk and sa.patientId_fk = p.personId_pk
       and (sa.notificationConfig_fk=nc.notificationConfig_pk and sa.patientId_fk = p.personId_pk)
       and (sa.occuranceDateTime IN (select max(occuranceDateTime) from systemAlertInfo where datediff(now(),occuranceDateTime)< 8 and    group by patientId_fk)) group by p.personId_pk;


I have written criteria query almost. But I do not know how to set the maximum of "occuranceDateTime " in the criteria.


Code:
               Criteria criteria = session
            .createCriteria(Person.class)
            .createAlias("personrolesByPersonIdFk", "person")
            .createAlias("person.roletype", "rtype")
            .createAlias(
               "patienthealthcareprovidersByPatientIdFk",
               "patHealthcareProv")
            .add(Expression.eq("rtype.roleTypePk", 1))
            .createAlias("systemalertinfosByPatientIdFk",
                  "patNotification")
            .createAlias("patNotification.notificationconfig",
                  "notifyConfig")
            .add(Expression.eq("patHealthcareProv.statuscode", STATUS))
            .add(Expression.eq("notifyConfig.category", CATEGORY))
            .add(Expression.between("patNotification.occuranceDateTime",
                  dateEarly, dateLater))
            .setProjection(
               Projections
               .distinct(Projections
                   .property("patNotification.personByPatientIdFk")));



Regards,
Sekar


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.