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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:36:38+00:00 2026-06-08T10:36:38+00:00

I have a noticication entity that has OneToMany relationship with its parameters, which is

  • 0

I have a noticication entity that has OneToMany relationship with its parameters, which is a list of NotificationParamEntity objects.

The code for both classes looks like:

// Notification Entity
@Entity
@Table (name = "NOTIFICATIONS")
public class NotificationEntity {
    ......
    @OneToMany (mappedBy = "notification")
    private List<NotificationParamEntity> params;
    ......
}

// Notification Parameter Entity
@Entity
@Table (name = "NOTIFICATIONS_PARAM")
public class NotificationParamEntity {
    ......
    @Column (name = "KEY", length = 40, nullable = false)
    @Enumerated (EnumType.STRING)
    private NotificationParameterEnum key;

    @Column (name = "VALUE", length = 4000, nullable = false)
    private String value;

    @ManyToOne
    @JoinColumn (name = "NOTIFICATION_ID", nullable = false)
    private NotificationEntity notification;
    ......
}

Now I can use the query below to get the notification that has a parameter named “P1” and with a value “V1”:

SELECT DISTINCT anEntity FROM NotificationEntity anEntity, IN
(anEntity.params) p WHERE p.key = “P1” AND p.value = ‘V1’

But when I want to find out the notification that has two specified parameters(P1=V1 and P2=V2), my query below failed to find anything:

SELECT DISTINCT anEntity FROM NotificationEntity anEntity, IN
(anEntity.params) p WHERE p.key = “P1” AND p.value = ‘V1’ AND p.key = “P2” AND p.value = “V2”

I can understand why it doesn’t work: there is no parameter that can have two different keys, so the query return nothing.

But how to make this work? Assume I have a notification entity that has two parameters, one is named P1 and value is V1, the other one is P2 and the value is V2, how can I find this notification entity with JPQL query?

  • 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-08T10:36:40+00:00Added an answer on June 8, 2026 at 10:36 am

    Try something like this:

    SELECT n FROM NotificationEntity n WHERE EXISTS 
         (SELECT p FROM NotificationParamEntity p WHERE p.key = 'P1' AND p.value = 'V1' 
         AND p.notificationEntity = n) 
    AND EXISTS 
         (SELECT p2 FROM NotificationParamEntity p2 WHERE p2.key = 'P2' AND p2.value = 'V2' 
         AND p2.notificationEntity = n)
    

    Note that it requires a reference from NotificationParamEntity to NotificationEntity (I don’t see that column in the snippet of your code, but you should have it, a @ManyToOne).

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

Sidebar

Related Questions

So I have a entity Notification , that has a boolean attribute readStatus to
in my Core Data model, I have an entity which has got a date
I have this code @Entity @Table(name = picture) public class Picture implements Serializable {
I have a notification which should give me some parameters when opening an activity
I currently have a notification in my Android application that has a PendingIntent so
I have a Person entity which belongs to a Department in a one to
I have two entities event and time. The event entity has a 1 to
I have an attribute modificationDate in my Entity A. I want to set its
I have a list of users which needs to be iterated using a foreach
I have JPA code that compiles fine in eclipse Helios and works fine in

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.