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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:28:49+00:00 2026-06-16T04:28:49+00:00

I have a column destined to hold a timestamp which is defined with a

  • 0

I have a column destined to hold a timestamp which is defined with a java.util.Date data type and stored in a Oracle DATE type in the database. I’ve verified that the full date and time information is persisted and retrieved correctly from the database, but when I try to compare it in a NamedQuery, the time information appears not to taken into account in the comparison.

The column is defined as follows (analyzeDate is of type java.util.Date):

@Basic(optional = false)
@Column(name = "ANALYZE_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date analyzeDate;

And my NamedQuery:

@NamedQuery(name = "BOADocument.findByBeforeAnalyzeDate", 
    query = "SELECT b FROM BOADocument b WHERE b.companyId = :companyId AND b.analyzeDate < :analyzeDate")

Which I then execute, passing analyzeDate which is of type java.util.Date:

List<BOADocument> docs = em.createNamedQuery("BOADocument.findByBeforeAnalyzeDate") 
            .setParameter("companyId", clientRecord)
            .setParameter("analyzeDate", analyzeDate, TemporalType.TIMESTAMP)
            .getResultList()

I get back a list of all of the lines in the Document table, although they all have exactly the same value for analyzeDate as the value I’ve set as a parameter to the NamedQuery.

If I inverse the comparison, I get no lines, further convincing me that the time portion of the timestamp is being lost on the b.analyzeDate side of things, not the :analyzeDate side of things.

I’m using JPA 1.0 with Hibernate 3.5.

This is stumping me, and I’m close to giving up and using a native query, but that feels like cheating!

  • 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-16T04:28:50+00:00Added an answer on June 16, 2026 at 4:28 am

    It turns out that the underlying Oracle type must be TIMESTAMP.

    DATE holds hour, minute and second information. This is enough precision for my purposes, so I was planning on using it instead of TIMESTAMP, which also holds milliseconds. As I mentioned previously, storage and retrieval of the hour, minute, and second information to and from DATE was working perfectly, but not comparisons based on the time data in named queries.

    I changed the database column type and voila, the code as previously written works. I also get the milliseconds saved, of course, but this doesn’t present any side effects in my code.

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

Sidebar

Related Questions

I have a MySQL database, there's a table which have column Time's Type is
I store dates in my database in a column of date data type. Let's
In database table I have column called options . It has type of integer
I have column in mysql DB which contains serialized data (used PHP JSON encode
My database have column MyId which is INT PK. In mapping file I have
I have this problem. In table I have column which is nvarcar type. and
In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
i have column named postDate defined as timestamp. when i print it directly: echo
I have column: LASTTOUCH TIMESTAMP(9) NOT NULL ENABLE and I must set current date
I have column in a postgresql database. They are lottery numbers. Four digits in

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.