Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:13:58+00:00 2026-06-08T09:13:58+00:00

I have a group with a one to many relationship with users. (A group

  • 0

I have a group with a one to many relationship with users. (A group can have zero or 1+ users)

I was to write a jpa query that returns a groups if it has not users attached or if it does have users the id matches my id.

For example if I have group 1 contain user 1 and user 2. group 2 containing no users.

If I was user 3 I want to return group 2 only.

If I was user 2 then I want to return group 1 and group 2

Can I do this in JPA? I know about the IS EMPTY part of JPQL so I can get group 2 returned regardless of user. My problem is how to query inside the list.

Any pointers would be good.

Thank for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:13:59+00:00Added an answer on June 8, 2026 at 9:13 am

    I think I have it. The answer is to left join with the list.

    For example

    SELECT g FROM Groups g left join fetch g.users u where (g.users IS EMPTY OR (u.id = :id))
    

    Groups is my entity which contains a list of users

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a many-to-many relationship between the entities Groups and Contacts. One group can
I have two tables, that relate via a one-to-many relationship i.e tableOne (1)----------(*) tableTwo
I have two classes, the Group class has a many to many relationship with
I have two tables, users and groups . A user can belong to many
Say I have a one-to-many relationship between clients and addresses. Clients can have multiple
I have 2 many to many relationship tables; Posts and Categories. One post can
I have a successful query that currently returns all data except for one table.
I have 2 related MySQL tables in a one to many relationship. Customers: cust_id,
i have many to many relationship between employee and group. following linq statement int[]
I'm trying to link one table to itself. I have media groups which can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.