Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Postgresql boolean problems

I have object with boolean field like

@Entity

@Table(name = "USERS")
public class User {

    @Id
    @GeneratedValue
    @Column(name = "ID")
    private Integer id;

    @Column(name = "ACTIVE")
    private Boolean active = true;
}

AND query for creating

CREATE TABLE IF NOT EXISTS USERS(
   ID  SERIAL PRIMARY KEY,
   ACTIVE SMALLINT ,
   LOGIN  CHAR(255) NOT NULL,
   NAME   CHAR(255) NOT NULL,
   PASSWORD CHAR(255) NOT NULL,
   ROLE INTEGER NOT NULL REFERENCES ROLE(ID)
);

When i try to take a user object i have next exception ERROR: operator does not exist: smallint = boolean

like image 363
Volodymyr O Avatar asked Apr 08 '26 18:04

Volodymyr O


2 Answers

try adding :

@Type(type = "org.hibernate.type.NumericBooleanType")
like image 198
Rastislav S Avatar answered Apr 10 '26 08:04

Rastislav S


In PostgreSQL, SMALLINT maps to Short and BOOLEAN maps to Boolean (hence the name).

You get to decide whether to change the class or the table.

like image 34
Kayaman Avatar answered Apr 10 '26 07:04

Kayaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!