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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:07:54+00:00 2026-06-01T06:07:54+00:00

I’m wondering if there is any JPQL construct that might help me with this

  • 0

I’m wondering if there is any JPQL construct that might help me with this problem:

Imagine simple M-N relationship of Chat and User (user might be present in multiple chat-s).

public class ChatEntity implements Serializable {

@ManyToMany(targetEntity = UserEntity.class)
@JoinTable(name = "CHATS_USERS",
        joinColumns = @JoinColumn(name = "CHAT_ID"),
        inverseJoinColumns = @JoinColumn(name = "USER_ID"))
private Collection<User> users;

}

Lets imagine these data (C1..CN = chat IDs, U1..UN = user IDs)

c1 ~ {u1, u2, u3} // in chat1 is user1, user2 and user3
c2 ~ {u1, u3}
c3 ~ {u2, u3}

Now I want to select such chat which has exact same collection of users i will pass to the query. E.g.

{u1, u3} -> c2
{u1, u2, u3} -> c1
{u1, u2} -> NULL (no result)

I found MEMBER OF constuct which seems nice. E.g.

SELECT c FROM Chat c WHERE (:u1 MEMBER OF c.users) AND (:u2 MEMBER OF c.users)
    ... AND (:uN MEMBER OF c.users)

But now there are two problems

  1. This is not correct so far because {u1, u3} will return both c1 and c2 and not only c2 as expected

  2. I got the collection of users and I don’t know if there is a way how to “decompose” such collection to multiple AND clauses in named query (static definition of query) or if there is any JPQL construct which will help me with this. E.g. something like

    … WHERE :users = c.users

  • 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-01T06:07:56+00:00Added an answer on June 1, 2026 at 6:07 am

    So… you want the users to only include those Users?

    Perhaps also include

    AND size(c.users) = 3
    

    Or maybe,

    Select c from Chat c join c.users u where not exists (Select u from User u2 where u = u2 and u.id not in :ids)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.