Hello there,
I've discovered some unexpected behavior recently on one of our data synchronization API endpoints.
We use a MySQL database and the Timestamp fields are defined with millisecond precision TIMESTAMP(3).
Problem
Let's assume we have a Timestamp of "2020-05-13 09:25:00.253" in the "updated_at" field on the database.
Querying the database with a Finder as follows will still return this entry, even though it should not.
dummy code
String format = "yyyy-MM-dd'T'HH:mm:ss.SSS"
DateFormat formatter = new SimpleDateFormat(format);
Date parsedDate = formatter.parse("2020-05-13T09:25:00.520");
Timestamp timestamp = new Timestamp(parsedDate.getTime());
find.query().where().gt("updated_at", timestamp).findList();
It seems that the millisecond precision is lost, when Ebean converts the timestamp passed into the
gt() method back to a string internally (?).
We fixed the issue by doing the Timestamp-To-String conversion ourselves and pass the timestamp as String (with millisecond precision) into the gt() method.
Question
Is this a bug in Ebean or is this expected behavior?
Do I have to configure something in Ebean so the timestamps are converted correctly?
Hint
I found out about this issue when I logged the SQL Queries, and executed them directly against the MySQL database. Which got me different results.
select t0.id, t0.updated_at from example where t0.updated_at > ?; --bind (2020-05-13 09:25:00.520) The timestamp was displayed with millisecond precision in the
bind(...) part, but it still returned timestamps in the same second with lower milliseconds.
Versions
Sbt-Plugin
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "5.0.0")
Playframework