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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:21:36+00:00 2026-06-12T19:21:36+00:00

I have a simple entity class that has a Date property. This property corresponds

  • 0

I have a simple entity class that has a Date property. This property corresponds to a MySQL datetime column.

@Entity
public class Entity {

    @Column(name = "start_date")
    @Temporal(TemporalType.TIMESTAMP)
    private java.util.Date startDate;

}

This is what an integration test I wrote looks like:

java.util.Date now = new java.util.Date();
Entity entity = new Entity();
entity.setStartDate(now);
entityService.save(entity); // save entity to database
entity = entityService.get(entity.getId()); // get entity back from database
Assert.assertEquals(entity.getStartDate(), now);

I would expect those two dates to be equal but they are not! Actually, I have :

now.getTime() = 1350160029831
entity.getStartDate().getTime() = 1350160029000

so there is a small gap between the two dates. I am really wondering where this gap could come from. It is not always the same and varies each time I start the testing process.
In my database, the date stored is 2012-10-13 22:15:38.0.

Do I really need to clear milliseconds somewhere?

  • 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-12T19:21:38+00:00Added an answer on June 12, 2026 at 7:21 pm

    From the MySQL documentation:

    A DATETIME or TIMESTAMP value can include a trailing fractional
    seconds part in up to microseconds (6 digits) precision. Although this
    fractional part is recognized, it is discarded from values stored into
    DATETIME or TIMESTAMP columns. For information about fractional
    seconds support in MySQL, see Section 11.1.5.6, “Fractional Seconds in
    Time Values”.

    Note that you shouldn’t use equals to compare dates anyway, because the various Date subclasses have buggy implementations, which cause problems such as a.equals(b) && !b.equals(a):

    java.util.Date d1 = java.sql.Date.valueOf("2012-01-01");
    java.util.Date d2 = new java.util.Date(d1.getTime());
    java.util.Date d3 = new java.sql.Timestamp(d1.getTime());
    
    System.out.println(d1.equals(d2)); // true
    System.out.println(d2.equals(d1)); // true
    System.out.println(d1.equals(d3)); // true
    System.out.println(d3.equals(d1)); // false
    System.out.println(d2.equals(d3)); // true
    System.out.println(d3.equals(d2)); // false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple class that provides state codes like this: public class StateProvider
In my Hibernated system, I have a class Picture that has some simple data,
Let's say I have a product class that has a Category property on it.
I have a quite simple doctrine entity that represent a news ; this news
I have implemented a simple entity ejb with a @version annotation. I expect that
I have a simple XCDataModel that contains one Entity with One Attribute. Essentially, I
I have a number of simple controller classes that use Doctrine's entity manager to
I have a terrible problem that hopefully has a very simple answer. I am
I have a class that takes an IRepository in its constructor like this ...
I have a simple JPA entity that uses a generated long ID as its

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.