Reputation:
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;
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.
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!
Upvotes: 0
Views: 5962
Reputation: 371
Add below annotation above the field name, if using hibernate
@Type(type = "org.hibernate.type.NumericBooleanType")
@Column(name = "is_active")
private boolean isActive;
Upvotes: 0
Reputation: 21391
You can use Hibernate's NumericBooleanType like so:
@Type(type = "numeric_boolean")
@Column(name = "is_active")
private boolean isActive;
Upvotes: 1