在 Postgresql 中,我有一个类型为 BIT(1) 的列。在 JPA 映射中,它就像:
@Column(columnDefinition="bit(1)")
private String type;
但是,当我执行测试时,出现此错误:
错误:列“type”的类型为位,但表达式的类型为字符变化 提示:您将需要重写或转换表达式。 排名:117
我尝试过其他 Java 类型:char、int、Boolean 和 BitSet。但是,同样的错误发生了。
你知道如何将 Postgresql 类型 BIT(1) 映射到 Hibernate JPA 吗?
最佳答案
Hibernate 不支持 PostgreSQL 的类型位。 尝试使用 spring JPA 的 native 查询和强制转换。例如:
@Modifying @Query(value = "update table set is_active = cast(:is_activeas bit) where id = :id", nativeQuery = true)
int updateTable(@Param("is_active") int isActive, @Param("id") long id);
关于java - BIT(1) HIbernate JPA 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20284674/