I'm trying to map with JPA (EclipseLink provider) a postgreSQL ENUM type to Java enum type (and vice versa).
I know I can easily map a Java enum to a varchar type in my postgreSQL database with the @Enumerated annotation but I want to map it in a postgreSQLENUM tpye. I think I must use a custom EclipseLink converter to do this.
So, I started to implement a org.eclipse.persistence.mappings.converters.Converter but I don't kown how to implement the convertObjectValueToDataValue, the initialize and the isMutable methods...
Can someone explain me how to implement these methods please ?
For now, my class is this one :
public class EnumConverter implements Converter {
private static final long serialVersionUID = 1L;
public Object convertDataValueToObjectValue(Object object, Session session) {
if(object instanceof PGobject){
return LangageEnum.valueOf(LangageEnum.class, ((PGobject)object).getValue());
}
return null;
}
public Object convertObjectValueToDataValue(Object object, Session session) {
// WHAT HERE...?
// I tried to play with PGObject witout success...
return object;
}
public void initialize(DatabaseMapping arg0, Session arg1) {
// WHAT INITIALIZATION HERE...?
}
public boolean isMutable() {
// TRUE OR FALSE AND WHY...?
return false;
}
}
@Converter(name="langageConverter", converterClass=EnumConverter.class)
@Convert(value="langageConverter")
private LangageEnum langage;
Thanks for explanations, I searched for custom converters for EclipseLink with Google but this time Google was not my friend.