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中可以为空。所以它不会返回任何结果。有没有什么办法在创建别名之前执行空检查?
感谢您宝贵的时间。