ActiveObjects datetime with full precision in MySQL

I can create a java.util.Date field in an Active Objects Entity like this:

@Table("EXAMPLE")
public interface Example extends Entity {
    Date getExampleField();
    void setExampleField(Date exampleField);
}

Based on this ancient piece of Active Objects documentation, this will create a timestamp on Postgres, and on MySQL, will create a datetime. This is also what I see in testing.

Based on the MySQL documentation, by default datetime’s drop millisecond precision:

The fsp value, if given, must be in the range 0 to 6. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0. (This differs from the standard SQL default of 6, for compatibility with previous MySQL versions.)

This is also what I see in testing.

However, internal Confluence tables (on MySQL) use datetime(6), so if I use a Confluence API to get the timestamp of, for instance, when a page was modified, store it in an ActiveObjects table, then try to correlate my ActiveObjects entity with the same Confluence API, I can’t do it because I’ve lost the millisecond precision.

There exists the @StringLength annotation for changing the length of varchar columns, but I can’t find a similar thing for specifying to the precision (fsp) for MySQL datetimes.

Are there any options for me to store a timestamp with the same precision that the internal Confluence table uses without using a String field in my Entity?

4 Likes

We looked at the Active Objects source more closely, and did not find anything. Huge bummer, given that Atlassian all but forces plugin authors to use ActiveObjects for creating tables.

Did you find an answer on this? I have the same results. I give a TIMESTAMP or a DATETIME field the correct format, including the milliseconds when I insert, but when I get rows from the table through forge sql, the milliseconds are gone. Since milliseconds are essential to me, I am instead saving the timestamp as a string:

const timestamp = new Intl.DateTimeFormat(“en-US”, {
year: “numeric”,
month: “2-digit”,
day: “2-digit”,
hour: “2-digit”,
minute: “2-digit”,
second: “2-digit”,
fractionalSecondDigits: 3,
timeZone: “GMT”,
timeZoneName: “short”,
}).format(new Date()).replace(“,”, “”).replace(" GMT", " GMT");

It works, but this is not easy to use in a where clause…

RB

No, unfortunately.

This is also what we ended up with. It’s not ideal, but it pays the bills. :slight_smile:

1 Like