-->
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: URGENt -->create alias collection
PostPosted: Tue Apr 24, 2007 10:42 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 10:19 am
Posts: 24
I have a table STUDENT that has a collection getDegrees().
In the table Degrees there are 3 fields
school, schoolDepartment, degreeType.

My problem is that I would like to execute a query based on the above 3 criteria.
But I would like to get all the students that have a specific (schoolId AND schoolDepartmentID) OR a specific degreeTypeId.

I am using the following criteria:

criteria.createCriteria("degrees", "jsdegrees");

Set schoolSet = new HashSet();
schoolSet.add(school);
criteria.add(Restrictions.in("jsdegrees.school", schoolSet));

Set schoolDepSet = new HashSet();
schoolDepSet.add(department);
criteria.add(Restrictions.in("jsdegrees.schoolDepartment", schoolDepSet));

Set postGradDegreeSet = new HashSet();
postGradDegreeSet.add(postGraduateDegreeType);
criteria.add(Restrictions.
in("jsdegrees.degreeType", postGradDegreeSet));



My problem is that it finds only the rows that have these 3 criterias satisfied. I used something like disjunction for the degreeType but it didn't work.

Any suggestions???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 10:58 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
This should work for you:

Code:
criteria.createCriteria("degrees", "jsdegrees");

Set schoolSet = new HashSet();
schoolSet.add(school);

Set schoolDepSet = new HashSet();
schoolDepSet.add(department);

Set postGradDegreeSet = new HashSet();
postGradDegreeSet.add(postGraduateDegreeType);

criteria.add(
             Restrictions.disjunction()
               .add(
                 Restrictions.conjunction()
                   .add(Restrictions.in("jsdegrees.school", schoolSet))
                   .add(Restrictions.in("jsdegrees.schoolDepartment", schoolDepSet))
                   )
               .add(Restrictions.in("jsdegrees.degreeType", postGradDegreeSet))
             )


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 5:12 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 11:39 am
Posts: 24
I have already tried it but it didn't work.
If for example the object STUDENT has 2 records of type DEGREE, and only if one of them satisfies the conjunction (school and schoolDepartment) and there is no value degreeType to satisfy the criterion in any of the 2 rows then I will have a result although it is something that it is wrong.


I want to have a result if both of these 3 criteria are satisfied, the school and schoolDepartment in the same row AND and the degreeType in another row or in the same.


Ananasi wrote:
This should work for you:

Code:
criteria.createCriteria("degrees", "jsdegrees");

Set schoolSet = new HashSet();
schoolSet.add(school);

Set schoolDepSet = new HashSet();
schoolDepSet.add(department);

Set postGradDegreeSet = new HashSet();
postGradDegreeSet.add(postGraduateDegreeType);

criteria.add(
             Restrictions.disjunction()
               .add(
                 Restrictions.conjunction()
                   .add(Restrictions.in("jsdegrees.school", schoolSet))
                   .add(Restrictions.in("jsdegrees.schoolDepartment", schoolDepSet))
                   )
               .add(Restrictions.in("jsdegrees.degreeType", postGradDegreeSet))
             )


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.