Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 45 java ee 8 java time OffsetTime java time OffsetDateTime I put this into context by first explaining how to support the Date and Time API without JPA 22 Because JPA 21 is capable only of working with older date constructs such as java util Date and java sql Timestamp a converter must be used to convert from data that is stored in a database to older date constructs supported by the JPA 21 release and then to the updated Date and Time API for use in an application A date converter in JPA 21 that is capable of performing such conversion might look like that in Listing 1 The converter in the listing is used to convert between LocalDate and java util Date Listing 1 @ Converter autoApply true public class LocalDateTimeConverter implements AttributeConverter LocalDate Date @ Override public Date convertToDatabaseColumn LocalDate entityValue LocalTime time LocalTime now Instant instant time atDate entityValue atZone ZoneId systemDefault toInstant return Date from instant @ Override public LocalDate convertToEntityAttribute Date databaseValue Instant instant Instant ofEpochMilli databaseValue getTime return LocalDateTime ofInstant instant
You must have JavaScript enabled to view digital editions.