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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:21:05+00:00 2026-05-27T06:21:05+00:00

How represent a date in a JPA query, without using (typed) parameters? If the

  • 0

How represent a date in a JPA query, without using (typed) parameters?
If the date is really fixed (for example, 1 mar 1980), the code:

TypedQuery<MyEntity> q = em.createQuery("select myent from db.MyEntity myent where myent.theDate=?1", db.MyEntity.class).setParameter(1, d);

having set:

Date d = new Date(80, Calendar.MARCH, 1);

is quite verbose, isn’t it? I would like to embed 1980/1/3 into my query.

UPDATE:
I modified the sample date to 1980/1/3, because 1980/1/1 as it was, was ambiguous.

  • 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-27T06:21:06+00:00Added an answer on May 27, 2026 at 6:21 am

    IIRC you can use date literals in JPQL queries just like you do it in JDBC, so something like:

    // d at the beginning means 'date'
    {d 'yyyy-mm-dd'} i.e. {d '2009-11-05'}
    
    // t at the beginning means 'time'
    {t 'hh-mm-ss'} i.e. {t '12-45-52'}
    
    // ts at the beginning means 'timestamp'; the part after dot is optional
    {ts 'yyyy-mm-dd hh-mm-ss.f'} i.e. {ts '2009-11-05 12-45-52.325'}
    

    should do the work (the curly braces and apostrophes are required).

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

Sidebar

Related Questions

Let's say I have a date that I can represent in a culture-invariant format
I represent dates using seconds (and microseconds) since 1970 as well as a time
How do i represent CRLF using Hex in C#?
How to represent the start and end times for one day? Using October 23,
I have 2 date object in the database that represent the company's working hours.
My program needs to represent this date as a java.sql.date object , but it
I haw two tables one is product and one is date. Date table represent
I have a question Can we convert date 20-06-2011 (dd-mm-yyyy) into 0611 using sql
I want to represent midnight by java.util.Date class. To check this I output this
I'm Using Oracle 11g and JPA 2.0 (hibernate in JBoss 6.0.0). I need 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.