0

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!

3
  • What don't you use a column with the boolean type? A bit is something different then a boolean You are not using an integer in Java either
    – user330315
    Jul 27, 2017 at 13:09
  • @a_horse_with_no_name : I have to use "1" for true values and "0" for false values. It's the code specification given to me.
    – user8221504
    Jul 27, 2017 at 13:13
  • Your question was "How to store boolean type into a column". The answer is "Use a column defined as boolean"
    – user330315
    Jul 27, 2017 at 13:15

2 Answers 2

1

You can use Hibernate's NumericBooleanType like so:

@Type(type = "numeric_boolean")
@Column(name = "is_active")
private boolean isActive;
0
0

Add below annotation above the field name, if using hibernate

@Type(type = "org.hibernate.type.NumericBooleanType")
@Column(name = "is_active")
private boolean isActive;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.