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 8432803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:13:11+00:00 2026-06-10T06:13:11+00:00

I have an entity which contains a list of other entities. For example it

  • 0

I have an entity which contains a list of other entities. For example it could be Person with a list of Address entities. The addresses are not specific to one person. (it is actually a many to many relationship with a join table in the middle in the DB)

I am doing a search to try and find all persons who do not have a an address with id X

(This might not make sense because of the triviality of the example. In my real world case it does 🙂 )

By named query is:

SELECT p FROM Person p left join fetch p.addresses a WHERE p.addresses IS EMPTY OR a.id != :addressId

addressId is the id of the address that I pass in

My problem is best explained with an example

  • Person 1 may have address 1 and address 2
  • Person 2 may have address 2
  • Person 3 may have address 3

and now the desired results

  • if I pass in address 1 then I want person2 and person 3 returned
  • if I pass in address 3 then I want person1 and person 2 returned
  • if I pass in address 2 then I want person 3 returned

Currently when I pass in address 1 I get all three back. I think this is because person 1 also has address 2 which means it gets through the query.

Does any one know how I can search for an id in the list and if it exist in any of the element then not return it?

Hope this makes sense. If not I can try and provide more details

Thanks

  • 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-10T06:13:12+00:00Added an answer on June 10, 2026 at 6:13 am

    You could just use this query:

    select p from Person p where not exists 
    (select a from Person pe left join pe.addresses a where p = pe and a.id = ?1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a db.BlobProperty property (called Icon) in my entity which contains an image
i have an entity-model file (edmx) file which contains few tables and few stored
I have an abstract entity called Block which contains two attributes: column and order
I have an Entity class, which contains 3 pointers: m_rigidBody, m_entity, and m_parent. Somewhere
I have Person entity which has composition with Location Entity @ManyToOne(fetch = FetchType.EAGER, cascade
I have a Core Data store which contains a number of MediaItem entities that
I have a Course entity which contains a Set of Keys to my Tag
I have a large list of entities which the user needs to be able
I have two entities ( Dataset and Item ), where the first one contains
In my Core Data app, I have an entity Person (which has a fullname

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.