【发布时间】:2016-05-06 11:58:05
【问题描述】:
我尝试将字符串值映射到 sql 枚举,但出现错误:
Caused by: org.postgresql.util.PSQLException: ERROR: column "state" is of type double_state, and the expression - character varying
我正在使用以下代码:
.hbm.xml 映射项
<property name="state" type="helper.entity.util.DoubleStateUserType">
<column name="state" not-null="true"/>
</property>
以下UserType实现nullSafeSet函数:
@Override
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index,
SessionImplementor session) throws HibernateException, SQLException {
if (null == value) {
preparedStatement.setNull(index, Types.VARCHAR);
} else {
preparedStatement.setString(index, (String) value);
}
}
表中的状态列是两个值的枚举。
【问题讨论】: