I've implemented an
AttributeConverter which works but seems that it shouldn't. By adding the
convert annotation to the target attribute, without specifying a converter class, the attribute converter just works.
shared abstract class Role(String role) of host | guest {
string => role;
}
shared object host extends Role("HOST") {}
shared object guest extends Role("GUEST") {}
entity
shared class Person(firstname, lastname, middle, role) {
id generated { strategy = auto; }
shared Int? id = null;
shared variable String firstname;
shared variable String lastname;
shared variable String middle;
convert//NOTE: Converter not specified
shared variable Role role;
}
converter//NOTE: autoApply not set and should false
shared class RoleConverter() satisfies AttributeConverter<Role, JString> {
convertToDatabaseColumn(Role role) => javaString(role.string);
convertToEntityAttribute(JString string) => if (string == "HOST") then host else guest;
}
At least none of the
documentation I've read shows anything similar in Java. While I'm happy with the behavior, as trying to follow the Java EE 7 documentation only yielded errors, I want know if it's correct and I can rely on it.
I'm using Ceylon 1.2.2 with EclipseLink 2.6.2