Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 46 java ee 8 ZoneId systemDefault toLocalDate In JPA 22 there is no longer a need for coding such a converter when you are using the supported date time types Support for those types is built in so you can simply specify the supported type on a field of an entity class without any further code The following code excerpt demonstrates this concept In the code note that there is no need to add a @ Temporal annotation because the type mapping occurs automatically public class Job implements Serializable @ Column name WORK_ DATE private LocalDate workDate Because the supported date time types are first class citizens of JPA they can simply be specified without the extra ceremony In JPA 21 the @ Temporal annotation must be specified on all persistent fields or properties of type java util Date and java util Calendar Although only a subset of the date time types is supported in this release an attribute converter can easily be generated for working with other types such as conversion between LocalDateTime and ZonedDateTime The biggest challenge to writing The JPA 22 update adds the useful ability of enabling attribute converters to become injectable such a converter is determining how to best make the conversion between the diferent types To make things even easier attribute converters are now injectable I show an example of injection in the next section
You must have JavaScript enabled to view digital editions.