问题描述
我的实体类中有一个类型为Boolean的变量,名称为isActive。它以名称is_active映射到列,数据类型为bit。
I have a variable of type Boolean in my entity class by name "isActive". It to mapped to a column by name "is_active" with data type as bit.
@Column(name = "is_active")
private boolean isActive;
但是当我尝试保存对象的isActive属性时,我收到一个错误:
But when ever I try to save isActive attribute of the object, I get an error:
column "is_active" is of type bit but expression is of type character
varying Hint: You will need to rewrite or cast the expression.
如何将值存储为isActive的值?当isActive的值为true时我想在数据库中存储1,而当isActive为false时我想存储0。
谢谢!
我尝试过的事情:
尝试了很多在线解决方案,比如使用@进行注释键入注释并向@Column注释添加各种属性,如
How do I store the values the values of isActive? I want to store "1" in the database when value of "isActive" is true and "0" when "isActive" is false.
Thank you!
What I have tried:
Tried many online solutions like annotating with @Type annotations and adding various properties to the @Column annotation like
@Column(name = "is_active" nullable=false, columnDefinition="TINYINT", length=1)
等。 。
推荐答案
这篇关于如何使用hibernate将boolean类型数据存储到postgresql db表中的数据类型为“bit”的列中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!