-->
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.  [ 3 posts ] 
Author Message
 Post subject: Right outer join and projection with Criteria API
PostPosted: Tue Sep 26, 2006 3:31 pm 
Newbie

Joined: Thu Oct 09, 2003 4:06 pm
Posts: 16
Ok, so this is probably a rare case, but what I'm trying to do is this:

There's an Exam entity and a TakenExam entity. The TakenExam entity references the Exam entity and a User who took the exam. There may be many TakenExam's for every Exam (or none). I'm trying to build a report of the available exams for a particular user with the information about whether they've passed the exam before, etc. Right now I'm doing this with an HQL query like this:

Quote:
select new eg.ExamInfo(exam.id, exam.name, exam.description, TakenExam.passed, takenExam.creationDate)

from PersistentTakenExam takenExam right outer join takenExam.exam exam

where takenExam.examinee = ? and exam.published = true


The association is one way, there's no association from Exam to TakenExam, so I'm doing a right outer join to get all of the exams with their corresponding TakenExams if they exist.

I'd really like to be able to model this using the Criteria API using the ResultTransformer to create my DTO object like the "select new" is doing above, but, although I found some posts about left outer join support in the Criteria API (and it only seems to be in the Criteria, not DetachedCriteria for some reason), there's nothing I could find for right outer join support. I'd like to create a DetachedCriteria for this so I can easily add more filters and ordering to the query at runtime. We've already got a bunch of infrastructure around adding these to a Criteria, and I don't relish doing string concatenation to try to get this working.

Any help appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 5:38 pm 
Newbie

Joined: Thu Oct 09, 2003 4:06 pm
Posts: 16
Hmm... I've also noticed that adding the user to the where clause is keeping the right outer join from getting Exams without TakenExams.... I can see how I could do this with SQL by adding the restriction of the user to the "on" of the right outer join, but I like the HQL "select new"...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 12:54 pm 
Newbie

Joined: Thu Oct 09, 2003 4:06 pm
Posts: 16
Is there a way to specify default values for selected values? Here's my current query, which works around the problem of the condition on TakenExam killing the outer-joinness of the outer join:

Quote:
select exam.id, exam.name, exam.description, exam.specialty, max(takenExam.passed), max(takenExam.creationDate)

from PersistentTakenExam takenExam right outer join takenExam.exam exam

where exam.published = true and
((takenExam is null) or (takenExam.examinee = ?))

group by exam.id, exam.name, exam.description, exam.specialty


I was trying to do this using a "select new eg.ExamInfo(...)" but I found that if the TakenExam is null (which is ok as per the right outer join) then the number of objects in the Object[] returned by the query is 4, not 6. It doesn't fill in the last 2 columns with null, it returns an array with only 4 elements, which, of course, breaks when it's passed to the constructor which is expecting 6...

Any ideas?

Also, I'd still like to be able to do this using the Criteria API, if anyone has any thoughts...


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

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.