We might also have a look at {{@Convert}} and {{@Converter}} of JPA 2.1. It is somehow similar to the third option. It also offers an auto-convert option which comes back to the original proposal. I kind of like the idea of aligning the two approaches.
Here are the examples from the JPA spec:
{code} @Converter public class BooleanToIntegerConverter implements AttributeConverter<Boolean, Integer> { ... }
@Entity public class Employee { @Id long id; @Convert(converter=BooleanToIntegerConverter.class) boolean fullTime; ... } {code}
{code} @Converter(autoApply=true) public class EmployeeDateConverter implements AttributeConverter<com.acme.EmployeeDate, java.sql.Date> { ... }
@Entity public class Employee { @Id long id; ... // EmployeeDateConverter is applied automatically EmployeeDate startDate; } {code}
|