0
我有連接三個表來獲取結果的查詢,但在某些情況下,對象可以爲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();
在上面的患者中,患者的詳細信息在PatientRemindersTO中可以爲空。所以它不會返回任何結果。有沒有什麼辦法在創建別名之前執行空檢查?
感謝您寶貴的時間。