Hello!

Resolution of system timestamps in JVM depends on Java version and 
operating system. Old versions of Java (Java 8 and older) provide only 3 
digits. Resolution was improved in Java 9, this version provides 7 digits 
on Windows, but only 6 digits on Linux, because it uses an old system 
function with this limitation. Java 15 and newer versions use a modern 
function and provide 9 digits instead of 6 on Linux.

There are two data types in the SQL Standard and H2 for datetime values 
with both date and time parts: TIMESTAMP 
<https://h2database.com/html/datatypes.html#timestamp_type> and TIMESTAMP 
WITH TIME ZONE 
<https://h2database.com/html/datatypes.html#timestamp_with_time_zone_type>. 
Both data types have default fractional seconds precision of 6 as required 
by the Standard and some database systems, including the H2, support larger 
precision.

(DATETIME is silently replaced with standard TIMESTAMP data type, actually 
you normally should use TIMESTAMP(9) WITH TIME ZONE for Instant values in 
H2 to avoid issues on DST or other time zone transitions.)

Instant values in Java also support up to 9 fractional digits. When you 
insert a value with non-zero nanoseconds into a column with lower 
fractional seconds precision, this value is rounded to that precision by H2 
(the SQL Standard doesn't specify an exact behavior, it only requires an 
implementation-defined rounding or truncation). When Hibernate reads it 
back it gets a rounded value instead of expected original one. To avoid it, 
you must define an explicit fractional seconds precision of 9 for this 
column.

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/a73f0faa-d9ae-4e2b-a408-9603c4efd0ban%40googlegroups.com.

Reply via email to