Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate 6+ Unable to map java enum to postgres enum

After upgrading to hibernate 6 I am having issues with postgres being able to save enum types. I am no longer able to use @TypeDef annotation as it was removed.

@Enumerated(value = EnumType.STRING)
@Type(MyPSQLType.class)
private MyType myType;

The postgres type is defined as

public class MyPSQLType extends org.hibernate.type.EnumType<MyType> {
    @Override
    public void nullSafeSet(PreparedStatement st, MyType value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
        st.setObject(index, value != null ? value.name() : null, Types.OTHER);
    }
}

This is the error I am now getting. Do I have to now register the custom type in a different way now that TypeDef is no longer applicable?

Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: my_type = character varying
  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
  Position: 187
like image 408
planktonchumbucket Avatar asked Aug 14 '26 06:08

planktonchumbucket


1 Answers

Using the hibernate 6 provided type resolved my issue

@Type(PostgreSQLEnumType.class)
like image 156
planktonchumbucket Avatar answered Aug 16 '26 06:08

planktonchumbucket