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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:21:10+00:00 2026-05-24T09:21:10+00:00

I have 2 tables (entity) a person entity and a vacation entity. One person

  • 0

I have 2 tables (entity) a person entity and a vacation entity. One person can have many vacations.

What I’m trying to do is the following query:

Select all the persons period!, but for the persons who have a vacations, I want to fetch all of the persons vacations which have a condition , lest just say startDate is between something.

Just to be clear no matter the constraints on the vacations I still want to get all the persons.this is my current HQL query:

select distinct p 
from Person as p 
left join fetch p.vacations as v 
where v.startDate between '2011-07-01' and '2011-07-30'

The problem with it is that it constraint my persons an returns only the ones who have a vacation that respects the condition….Can someone help please?

I have no problem if someone can tell me this in native SQL

UPDATE Resolved in native SQL thanks to @Quasdunk:

SELECT * 
FROM person as p 
LEFT JOIN 
     (SELECT * FROM vacation
      WHERE startDate BETWEEN '2011-08-01' AND '2011-08-30') as v ON v.person_id = p.id

My new problem is how to convert it to an HQL query so I can fetch the vacations for each person, and the persons to be distinct (the conditions remain the same).

  • 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-05-24T09:21:11+00:00Added an answer on May 24, 2026 at 9:21 am

    In native SQL this would be:

    SELECT * 
    FROM person 
    LEFT JOIN (SELECT * 
               FROM vacations 
               WHERE startDate BETWEEN '2011-07-01' AND '2011-07-30')
    

    untested, but you get the idea 🙂

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

Sidebar

Related Questions

I have tables linked by FK, I query on the first table using entity
i have the two classes Person and Attribut, in short: @Entity @Indexed @Table(name=persons) public
I have written the following code: @Entity @Table(name=person) @Inheritance(strategy=InheritanceType.JOINED) public class Person { private
I have the following property defined: @Entity @Table(name = person) public class Person extends
I have two tables called Person and Address . These tables I mapped one
i have one problem in one-to-many mapping using hibernate. i have 2 classes, Person
Ok, say i have a Person entity which needs to have Persons as property
I have two tables that are considered a single entity in my domain model.
I have two tables in my database schema that represent an entity having a
i have an entity-model file (edmx) file which contains few tables and few stored

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.