I wonder how to map with JPA Java enum and PostgreSQL enum type ?
In PostgreSQL side I have created this type :
CREATE TYPE langage AS ENUM ('FR', 'EN', 'DE');
And I have a Java enum :
public enum LangageEnum {
FR,
EN,
DE;
}
My JPA entity field is this one :
@Enumerated(EnumType.STRING)
@Column(name="langage")
private LangageEnum langage = LangageEnum.FR;
but I receive Exception :
Caused by: org.postgresql.util.PSQLException: ERREUR: la colonne « langage » est de type pretoria.langage mais l'expression est de type character varying Indice : Vous devez réécrire l'expression ou lui appliquer une transformation de type.
I think I can succeed using ObjectTypeConverter
as show here
but ObjectTypeConverter
is a EclipseLink
annotation, not JPA
so I'm looking for another way to do this.
So, how can I map Java enum to PostgreSQL enum please ?