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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:11:48+00:00 2026-06-01T22:11:48+00:00

I would like to make this query in JPA: SELECT * FROM `happyDB`.`users` U

  • 0

I would like to make this query in JPA:

SELECT * FROM `happyDB`.`users` U WHERE U.party_as_user =1 AND U.party_party_id =2

This is working fine, but my problem is that I have Party only as an object, not as an id and I can’t make it work.

In the Users-entity where I am trying to do the named query I have the following:

@JoinColumn(name = "pary_party_id", referencedColumnName = "party_id")
@ManyToOne
private Party partyId;

@Column(name = "party_as_user")
private Boolean partyAsUser;

I tried to implement it like an object with dot notation, but that’s not working:

@NamedQuery(name = "Users.findByPartyAsUser", query = "SELECT u FROM Users u WHERE u.partyAsUser = :partyAsUser AND u.partyId.partyId = :partyId")

There is a property called partyId inside the Party-object, but it’s not working. Is there any solution for that or do I have to add one property to the Users-bean like private int partyID and populate it every time when a new Party is inserted into Users?

Thanks for helping!
Sami Nurmi

  • 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-01T22:11:49+00:00Added an answer on June 1, 2026 at 10:11 pm

    In general you can use an object as a parameter in JPA,

    SELECT u FROM Users u WHERE u.partyAsUser = :partyAsUser AND u.party  = :party
    
    Party party = new Party(id);
    query.setParameter("party", party);
    

    But what you have should work if you use the correct variable names, my guess is,

    SELECT u FROM Users u WHERE u.partyAsUser = :partyAsUser AND u.party.id  = :id
    

    And you can always use a native SQL query, if you understand SQL better than objects.

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

Sidebar

Related Questions

How could I make this kind of query e.g. in MySQL SELECT * FROM
I would like to make qqplots through a list of dataframes. I wrote this
i would like to learn how to make PHP/CSS syntax generator. i assume this
I would like to make a php script that can capture a page from
I would like to make a query which needs to compare an property's property
I'm using EF4 and i need to make this query with LINQ but i
I would like to make a query for database user roles for all databases
I have this table : And I would like to make a request that
Is there a way to make this query faster: $qur = mysql_query( SELECT id,
I would like to do MySQL query like this: if((value1 != dbPrimaryValue1) OR (value2

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.