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
Using the hibernate 6 provided type resolved my issue
@Type(PostgreSQLEnumType.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With