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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:55:16+00:00 2026-06-02T16:55:16+00:00

I want to build up a query which search dates on different entites. My

  • 0

I want to build up a query which search dates on different entites. My structure is:

  • Contract has date (non nullable)
  • Employee has date (non nullable)
  • Employee may have a contract id (nullable)

If a Employee has a contract I want to retrieve the contract date. If an employee does not have a contract then I want to return the Employee date.

My code so far is:

if (inputDate!= null) {
    ParameterExpression<Date> exp = criteriaBuilder.parameter(Date.class, "inputDate");
    criteria.add(criteriaBuilder.or(
        criteriaBuilder.isNull(employee.get("contract")),
        criteriaBuilder.lessThanOrEqualTo(employee.<Date>get("creationDate"), exp),   criteriaBuilder.lessThanOrEqualTo((employee.join("contract").<Date>get("fromDate")), exp) ));}

This does not seem to work though. I always appear to go into the isNull which I do not expect.

I am happy to look into this some more but I guess my question is whether this is the correct way of going about it. Is it? I have seen a selectCase as well in criteriaBuilder so perhaps that may be a better solution.

Any pointers would be greatly received.

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-02T16:55:17+00:00Added an answer on June 2, 2026 at 4:55 pm

    Here would be a solution, not sure if it works, but we will manage to get it work with your help :):

    ParameterExpression<Date> inputDateExp = criteriaBuilder.parameter(Date.class, "inputDate");
    Predicate employeeCreationDate = criteriaBuilder.lessThanOrEqualTo(
            employee.<Date>get("creationDate"), inputDateExp);
    Predicate contractStartDate = criteriaBuilder.lessThanOrEqualTo(
            employee.join("contract").<Date>get("fromDate"), inputDateExp);
    
    criteria.add(
            criteriaBuilder.selectCase().when(employee.get("contract").isNull(), employeeCreationDate).otherwise(contractStartDate));
    

    I do not understand why use “inputDate” as Expression instead of a Date? Also, I suggest renaming criteria to c and criteriaBuilder to cb, this would save space and I think it is more comfortable.

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

Sidebar

Related Questions

I want to build a mySQL query, which returns all nodes in a graph
I want to build the following pseudo query Select a From APDU a where
I want to search through 250 files with a program which supports regex but
I want to build a query like SELECT username from users WHERE login_attempts >
I wonder how I can build a query expression which understands the given item
Let's pretend that we want to build an eBay like app in which we
I'm trying to build a query that will order results by date and time,
I have a search form built in ASP.NET that has a dropdown list which
I want to build a search with four search terms. I'm using Kohana 3.0.7
I want to build an dashboard for which back end will be Pentaho community

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.