I'm developping an API using Springboot and PostgreSQL 12. I created a user table with hibernate and the entity field that is problematic is the following:
@Column(columnDefinition = "BOOLEAN NOT NULL DEFAULT FALSE")
private Boolean emailVerificationStatus = false;
My table seems to be correctly generated :
create table users (
id int8 generated by default as identity,
email varchar(120) not null,
email_verification_status boolean default false not null,
email_verification_token varchar(255),
encrypted_password varchar(255) not null,
first_name varchar(50) not null,
last_name varchar(50) not null,
user_id varchar(255) not null,
primary key (id)
)
My issue is while running the application I receive an error message :
org.hibernate.PropertyValueException: not-null property references a null or transient value : fr.mycompany.app.io.entity.UserEntity.emailVerificationStatus
By default, when I create the user, it sends a null value. I can solve this issue by setting the value to false in my service layer but it's not very elegant. Also, When I remove the option nullable = false, it works fine but the value is set to null instead of getting the default value. It seems that postgresql doesn't take the default value (false) as value when I try to send a user to my API. I want to force changing null value to false by default.