in Education by
For four days now I´ve been trying to perform a query in my database. Heres the problem: I have a Group of Users Users can have birth date (it might be null) I want to list Groups that have no Users AND Groups that have Users in which all the users have 'null' for the birthdate I was able to get the Groups that have no Users easily (I did a left join), my problem is with the second part, getting groups where all users have null for the birthdate. So far this is the code I have: Criteria c = session.createCriteria(Group.class); c.createAlias("userCollection", "u", Criteria.LEFT_JOIN); c.add(Restrictions.or(Restrictions.isNull("userCollection"), Restrictions.isNull("u.birthDate"))); This works fine, but when a user in the group have a birthDate not null the group still appears in the query because others in the group have a null birthdate. I think I need to use not in, right? If anyone could help please, I tried a lot but I am getting a null pointer exception. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The easiest way to do this is to exclude groups that have users with non-null birthDate, which takes care of both conditions simultaneously (groups with no users would not be on this list due to inner join). So, something like: DetachedCriteria excludedGroups = DetachedCriteria.forClass(Group.class); excludedGroups.createAlias("userCollection", "u"); excludedGroups.add(Restrictions.isNotNull("u.birthDate")); excludedGroups.setProjection(Projections.id()); Criteria c = session.createCriteria(Group.class); c.add(Subqueries.propertyNotIn("id", excludedGroups)); BTW, doing this via HQL would be even easier.

Related questions

0 votes
    If I am trying to retrieve first array using (String) response.getProperty(0); but it was returning me ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    If I am trying to retrieve first array using (String) response.getProperty(0); but it was returning me ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    I'm trying to use createCriteria with OR on two nested objects. This is the code I'm working with ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    A non-correlated subquery can be defined as________ (a) A set of sequential queries, all of which ... Predicate Reads topic in division Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    What is a Subquery? What are its types?...
asked Dec 9, 2020 in Technology by JackTerrance
0 votes
    I'm working on Excel VBA macros and I want to retrieve data from a MS Access database (.accdb ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I have an XML file that starts like this: I'll have to open a lot of these files. Each of these ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    How could we retrieve a single value from data base using Groovy?...
asked Sep 25, 2021 in Technology by JackTerrance
0 votes
    have an issue with cocoapods/git. I'm trying to add new pod to the project and get the following ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    When creating a jQuery UI datepicker on a detached div it works fine in Firefox but in Chrome it gets ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I am writing a powershell script that will automate a dev environment deployment and I've hit a problem ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    I have made a commit and discarded it. I can still retrieve that commit using git reflog. A. True B. False...
asked Dec 24, 2022 in Education by JackTerrance
0 votes
    what i want : i have a config file where it contains some urls in .json file stored in asset ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    In the HTML of a web app, there is the following code What is actually shown on the page is a string displaying ... . Any help? Thanks. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am using jersey, and I want to send (in a POST) a list of objects to the server. This is ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
...