小编pla*_*ket的帖子

Hibernate 6+ 无法将 java 枚举映射到 postgres 枚举

升级到 hibernate 6 后,我遇到了 postgres 保存枚举类型的问题。我无法再使用@TypeDef注释,因为它已被删除。

@Enumerated(value = EnumType.STRING)
@Type(MyPSQLType.class)
private MyType myType;
Run Code Online (Sandbox Code Playgroud)

postgres 类型定义为

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我现在遇到的错误。既然 TypeDef 不再适用,我现在是否必须以不同的方式注册自定义类型?

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 …
Run Code Online (Sandbox Code Playgroud)

postgresql hibernate

6
推荐指数
1
解决办法
2453
查看次数

标签 统计

hibernate ×1

postgresql ×1