rajive.jha (8) [Avatar] Offline
#1
Hi,

I am populating an object say Employer.

Like :

Criteria criteria = session.createCriteria(Employer.class,"employerData").add(Restrictions.eq("employerId", employerId));
criteria = criteria.createAlias("employerData.person", "person",CriteriaSpecification.LEFT_JOIN).setFetchMode("person", FetchMode.JOIN);

criteria = criteria.createAlias("employerData.personEmployerEmployeeAssocs", "employee",CriteriaSpecification.LEFT_JOIN).setFetchMode("employee", FetchMode.JOIN);

..........
......... and more joins


there exists a relationship between employer and employees .. so there is a set of personEmployerEmployeeAssocs in Employer class ,

Now when i add a restriction
criteria = criteria.add(Restrictions.isNull("employee.effectiveEndDate"));

which means retrieve only those employees who are active (effectiveEndDate is null) .

now if no employees are active this breaks the entire query since it adds a condition in where clause .. where effective_end_date is null ... so employer object is returning null even though we have other details for employer object. Can we do something in hibernate like following in sql : effective_end_date(+) is null;

which will return employer object with other details .. but the set of employee will be null .

Please guide.

Thanks
Rajiv