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

  • Home
  • SEARCH
  • 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 6647999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:36:15+00:00 2026-05-26T00:36:15+00:00

In one of my projects I have the following situation: I have Availability Objects

  • 0

In one of my projects I have the following situation:

I have “Availability Objects” that have a starting date and an end date. Users query for these by defining a date range of their own.

The customer would basically like to output all Availabilities and sort them by the number of days that are matching in the date range of the availability and the users date range.

For example, if I have two Availabilities, Availability 1 from January 1st 2012 till January 31th 2012 and Availability 2 from January 1st 2012 till January 15th 2012 and the user queries for “Availabilities between Jan 1st 2012 and Jan 31th 2012” the result should be:

Availability   | numberOfDaysMatching
Availability 1 | 31
Availability 2 | 15

I cannot really wrap my head around how I would query for this without denormalizing the data. As the Persistence API I am using JPA, provided by Hibernate (3.6ish I think).

Right now my solution is to denormalize the Days an Availability is in, by calculating them on every store / update and basically storing each day in a seperate table. This way I can query for the wanted result by basically computing the days within the users query, looking them up in my days table and then querying for Availabilities where one of their Days is IN(:mycalculateddays).

Is there some non-monstrous way to query this with plain JQPL that does not denormalize the data like I did?

  • 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-26T00:36:15+00:00Added an answer on May 26, 2026 at 12:36 am

    Querying overlapping range itself is of course easy (assuming that ranges are valid(start <= end for both):

    SELECT r
    FROM Range r 
    WHERE  r.startDate <= :endDate and :startDate <= r.endDate
    

    But you cannot construct a query that computes difference between two Dates, because JPQL does not support arithmetic operations on Date. Also there is no built in functions that would help.

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

Sidebar

Related Questions

I have the following code in one of our projects webpages: XmlDocument xDoc =
I have the following two projects in in Flex Builder 3: One AS3 library
I have the following situation I have one swt class which displays a simple
Let's say I have one project with the following POM: <groupId>com.mine</groupId> <artifactId>coreJar</artifactId> <packaging>jar</packaging> <version>0.0.1-SNAPSHOT</version>
I currently have the following in one solution: Core Project (data access, biz logic,
I have two projects.One project is build in MVC asp.net and the other project
I have a solution with 3 projects.One of UI (contains web pages) and one
I have the digdog MapKitDragAndDrop in one my projects to achieve drag and drop
I have a Visual Studio C++ solution with 3 projects: one contains all classes
I have upgraded one of my projects in c# from visual studio 2005 to

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.