-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: One to One relationship - isNull semantics
PostPosted: Sun Feb 26, 2006 9:51 am 
Newbie

Joined: Wed Oct 12, 2005 4:39 pm
Posts: 15
Location: India
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.