[h2] Re: [Spring bot3 + h2 v.2.1.214] H2 failing to fetch Java Instant.
You are right! Creating a custom converter solved the issue. I'm not sure tho why did this issue pop-up only now. Thank you so much for the help! Have a great day! On Monday, April 24, 2023 at 10:36:14 AM UTC+3 Evgenij Ryazanov wrote: > MySQL mentioned in your question on StackOverflow doesn't have the TIMESTAMP > WITH TIME ZONE data type. It means your application uses different data > types with different database systems. > > JDBC drivers by default return TIMESTAMP values as java.sql.Timestamp > (R2DBC returns them as java.time.LocalDateTime). > > Both JDBC and R2DBC drivers return TIMESTAMP WITH TIME ZONE values as > java.time.OffsetDateTime. > > spring-data-commons is able to convert LocalDateTime to Instant, but it > doesn't have a built-in converter from OffsetDateTime to 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/2bf4175f-6ab6-4f6c-80c2-29ebbbff87fdn%40googlegroups.com.
[h2] Re: [Spring bot3 + h2 v.2.1.214] H2 failing to fetch Java Instant.
MySQL mentioned in your question on StackOverflow doesn't have the TIMESTAMP WITH TIME ZONE data type. It means your application uses different data types with different database systems. JDBC drivers by default return TIMESTAMP values as java.sql.Timestamp (R2DBC returns them as java.time.LocalDateTime). Both JDBC and R2DBC drivers return TIMESTAMP WITH TIME ZONE values as java.time.OffsetDateTime. spring-data-commons is able to convert LocalDateTime to Instant, but it doesn't have a built-in converter from OffsetDateTime to 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/7ea3c19b-1c56-4148-a690-b9d2b66520aen%40googlegroups.com.
[h2] Re: [Spring bot3 + h2 v.2.1.214] H2 failing to fetch Java Instant.
I see what you are saying, the thing is, outside of the tests, the queries are working perfectly as they are, and before the version updates it worked fine in tests as well. The fact that the problem only shows up when using h2 made me think that it is a h2 related problem. On Friday, April 21, 2023 at 6:51:57 PM UTC+3 Evgenij Ryazanov wrote: > 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/6023ea5a-059e-4538-a23c-bb1ea9720edan%40googlegroups.com.
[h2] Re: [Spring bot3 + h2 v.2.1.214] H2 failing to fetch Java Instant.
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.