Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 48 java ee 8 CDI improvements made throughout the Java EE 8 specifications such as the enhanced JSF converters because they can also now use CDI injection To use this new feature simply inject CDI resources into an attribute converter as needed Listing 2 demonstrates an example of an attribute converter and now I will walk through it to point out the important pieces The converter class must implement the javax persistence AttributeConverter interface passing an X and Y value The X value should correspond to the data type in the Java object and the Y value should correspond to the database column type Next the converter class should be annotated with @ Converter Finally the class should override the convertToDatabaseColumn and convertToEntityAttribute methods The implementation in each of these methods should convert the values to and from the specified types To automatically apply the converter each time the specified data type is used specify automatic as in @ Converter autoApply true To apply the converter to a single attribute use the @ Converter annotation at the attribute level as shown here @ Convert converter LocalDateConverter java private LocalDate workDate A converter can also be applied at the class level as follows @ Convert attributeName workDate converter LocalDateConverter class public class Job implements Serializable The scrollable ResultSet and pagination techniques fetch only a portion of the data at one time which might be better with large datasets
You must have JavaScript enabled to view digital editions.