3

I am trying to map a PostgreSQL table in hibernate. I am writing a POJO class. There is one column with BIT VARYING type. How to declare java data type for getters and setter method in POJO class?

Object and byte[] are not working.

0

1 Answer 1

1

Use integers. Take the following simple example where I give bits representation for three different values as integers.

create table bits_comparison_test (
  string VARCHAR(10),
  bits INTEGER
);

insert into bits_comparison_test (string, bits) values ('Studio', 1); -- binary 001
insert into bits_comparison_test (string, bits) values ('Apartment', 2); -- binary 010
insert into bits_comparison_test (string, bits) values ('House', 4); -- binary 100

And then if we want Apartments and Houses, we can execute the following query:-

select * from bits_comparison_test where bits & 6 != 0;

Make sure that your binary representation, for each type, has only one 1 bit. For example if you represent houses by 3 (which is 11 binary), you can't know if the user wants houses or only (studios and apartments) together.

Sign up to request clarification or add additional context in comments.

1 Comment

Good hint. But the original question was about Hibernate and a Java type.

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.