1

Now, the data type of the variable in my Java class is "boolean". I want to store it in a PostgreSQL table. The column in which I want to store my data has data type defined as "bit". But when I try to save the object which has this boolean variable, I get the error:

ERROR: column "isdeleted" is of type bit but expression is of type boolean

I'm using Hibernate to store the data. My code snippet for defining and mapping my variable:

@Column(name = "isDeleted")
private boolean isDeleted;

How do I save my object? Thank you!

1

4 Answers 4

2

Please use a proper boolean type in Postgres. Although it is possible to store boolean values in bit streams, it makes later usage complicated.

With the usual boolean you can do this:

SELECT * FROM table WHERE isdeleted;

Whereas with bit type you have to do bitwise operations:

SELECT * FROM table WHERE isdeleted > B'0'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for responding! I know that and I want to, but this is the specification given to me. I can't make any changes to the table schema.
2

Try using BOOLEAN data type, define your @Column annotation like that:

@Column(name = "isDeleted", columnDefinition = "boolean default true", nullable = false)
private boolean isDeleted = true;

Also, I think in NHibernate the column type is TrueFalse, which expects 'T' or 'F'. You would need to change the column type to Boolean. Try this link

1 Comment

Sorry, can't make changes to the specifications!
0

Try adding PostgreSQL Dialect in your code "org.hibernate.dialect.PostgreSQLDialect"

Comments

0

Add below annotation above the field name, if using hibernate

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.