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.
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.