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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:33:55+00:00 2026-06-10T11:33:55+00:00

I have a two entities that are related like so. public class User {

  • 0

I have a two entities that are related like so.

public class User {
    @Column(name = "ID")
    private Integer id;
    @OneToMany(mappedBy = "customerUserId")
    private Collection<FlightBooking> flightBookingCollection;
}
public class FlightBooking {
    @Column(name = "ID")
    private Integer id;
    @Column(name = "STATUS")
    private Integer status;
    @JoinColumn(name = "CUSTOMER_USER_ID", referencedColumnName = "ID")
    @ManyToOne
    private User customerUserId;
}

I wan’t to return all users but only flights that have a status = 1.

So far I have:

SELECT u FROM User u LEFT JOIN u.flightBookingCollection AS fb WHERE fb.status = 1

But that only returns users that have at least one flightBooking with status of 1.

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-10T11:33:57+00:00Added an answer on June 10, 2026 at 11:33 am

    That is fundamentally wrong approach. JPA mappings are about defining data model, not about defining structure of specific query result. This means that User should have all (in the case of eager fetching) elements of flightBookingCollection loaded when returned as a result of query, not just some of them.

    If there is need for other kind of results, dedicate object to present result must be created with appropriate constructor and created with SELECT NEW construct. Examples can be found from this question.

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

Sidebar

Related Questions

I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have two entities like this: public class Service { public virtual int ServiceId
I have two related entities, say @Entity public class Book { @ManyToOne Shelf shelf;
Say I have two entities in Doctrine2 that are related to each other, Models\User
I'm using core data in my app. I have two entities that are related:
Consider the following scenario We have a simple database that involves two entities: user
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities A and B that are related in a MxN relation
I have two entities - UserObj and Producer. UserObj stores user-related profile data Producer

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.