Hibernate version: 3.x
I have a One-to-One mapping between two objects - enquiry and enrollment. Enquiry Object mapping has an entry like:
<one-to-one name="enrollment" foreign-key="enquiryId" class="businessobject.enrollment.StudentEnrollment" />
And StudentEnrollment has its own hibernate mapping defined.
My problem is that using HQL semantics of "is null" is not working on this.
The following statement would NOT work:
Code:
select count(*) from StudentEnquiry as E where E.enrollment is null
Hibernate FAQ tells me to use left join to sort this problem out. For some reason, "is Null" does not seem to work with one-to-one mapping. I can not see any fundamental reason for this to be not supported. Anyways, I am happy that what they suggest as a work around surely works:
Code:
select count(*) from StudentEnquiry as E left join E.enrollment enr where enr is null
Can someone explain why "is Null" does not work directly with one-to-one mapping?
Second question:
I am not able to do anything about the criteria to check for all enquiries whose enrollments are not null. Business wise, I want to find out all students who enquired but did not come back and enroll.
Code:
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Criteria criteria = session.createCriteria(StudentEnquiry.class);
criteria.createCriteria("enrollment").add(Expression.isNull("enrollment"));
List list = criteria.list();
tx.commit();
System.out.println("List Size = "+list.size());
The above code is simply not running. What should I do with the criteria API to list only those enquiries whose enrollment field is null?
Thanks.
Best Regards,
Raghu