2017-04-24 7 views
0

結果を得るために3つのテーブルを結合するクエリがありますが、オブジェクトがnullになることがあります。この場合、結合を避ける必要があります。 PatientRemindersTO上記patientTO.patientId詳細にオブジェクトがnullでない場合のみ、Hibernate結合

Criteria patientCriteria = session.createCriteria(PatientRemindersTO.class); 
patientCriteria.createAlias("patientTO", "patientTO"); 
patientCriteria.createAlias("doctorTO", "doctorTO"); 



patientCriteria.setProjection(Projections.distinct(Projections.projectionList() 
          .add(Projections.property("patientRemindersId")) 
          .add(Projections.property("doctorTO.doctorId")) 
          .add(Projections.property("doctorTO.phoneNumber")) 
          .add(Projections.property("patientTO.patientId")) 
          .add(Projections.property("patientTO.Mobile")) 
          .add(Projections.property("reminderSettingsType")) 
          )); 

DetachedCriteria fcCriteria = DetachedCriteria.forClass(PatientRemindersScheduleTO.class,"patientRemindersScheduleTO"); 
fcCriteria.add(Restrictions.eq("patientReminderScheduleActive",'Y'));           
fcCriteria.setProjection(Projections.property("patientRemindersScheduleTO.patientRemindersId")); 

patientCriteria.add(Subqueries.propertyIn("patientRemindersId", fcCriteria)); 

List results = patientCriteria.list(); 

nullにすることができます。したがって、結果は返されません。エイリアスを作成する前にヌルチェックを実行する方法はありますか?

あなたの貴重な時間をありがとう。

答えて

1

この場合、LEFT_OUTER_JOINを使用してください。 ので、あなたの基準が好きになる - >

Criteria patientCriteria = session.createCriteria(PatientRemindersTO.class); 
patientCriteria.createAlias("patientTO", "patientTO", Criteria.LEFT_OUTER_JOIN)); 
patientCriteria.createAlias("doctorTO", "doctorTO", Criteria.LEFT_OUTER_JOIN)); 

hereドキュメントである、あなたはそれについての詳細を見つけることができます。

関連する問題