Hello!

This problem is not related to H2 at all.

H2 by itself can return TIMESTAMP WITH TIME ZONE and compatible values as 
java.time.Instant from its JDBC driver if it is explicitly requested.

try (Connection c = DriverManager.getConnection("jdbc:h2:mem:")) {

ResultSet rs = c.createStatement().executeQuery("VALUES TIMESTAMP WITH TIME 
ZONE '2023-01-02 03:04:05.123456789+00'");

rs.next();

System.out.println(rs.getObject(1, Instant.class));

}

But when you use some library on top of JDBC, you need to ensure that this 
library also supports java.time.Instant values. This Java type is not a 
part of JDBC specification and only few drivers (including driver of H2) 
support it natively. Java persistence libraries also aren't required to 
know this data type. It looks like you need to write an own data type 
converter. For example, in JPA, converters implement 
jakarta.persistence.AttributeConverter or 
javax.persistence.AttributeConverter depending on version of JPA 
implementation. In your case an implementation of 
org.springframework.core.convert.converter.Converter seems to be required. 
spring-data-commons project has 
org.springframework.data.convert.Jsr310Converters class with some 
converters for java.time.Instant type, but it doesn't have a converter 
between java.time.OffsetDateTime (JDBC data type for TIMESTAMP WITH TIME 
ZONE SQL data type) and java.time.Instant.

-- 
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/5aeff1b3-0650-4243-b9a7-4036c9fd3f89n%40googlegroups.com.

Reply via email to