2
votes

From my understanding nullable = false(let say for column customerid) is only useful for creating schemas using hibernate and it should not do any kind of validation before persisting. My database column has no such constraint(it can take null values), while persisting the entity with customerid null, getting this error

Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value :b
    at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:111) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
    at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:55) ~[hibernate-core-5.4.27.Final.jar:5.4.27.Final]
    at 

This error started keep coming after i update my spring boot version to 2.4.2

Entity class

public class FaceIndexResponse extends AuditEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(name="customer_id",nullable = false)
    private String customerId;
    @Column(name="application_id")
    private String appid;}

Service class where i was trying to save the above entity

public IndexFacesResult handle(FaceIndexModel model) throws IOException{
    FaceIndexResponse response=new FaceIndexResponse();
    response.setAppid(model.getApplicationId);
    faceIndexResponseJpa.save(response);
 }


                                   Table "public.face_index_response"
     Column     |            Type             | Collation | Nullable |             Default              
----------------+-----------------------------+-----------+----------+----------------------------------
 id             | integer                     |           | not null | generated by default as identity
 customer_id    | character varying(64)       |           |          | 
 application_id | character varying(64)       |           |          | 
1
can you share the code from which this exception is thrown? - Naqi
i was trying to save the entity using springJpa where customerid was null. - NubMaster
have you check the database table? Reconfirm that the column is nullable in database. Make sure to refresh any database client window you have already opened. - Naqi
yes column in database table does not contain any constraints. - NubMaster
Strange. I always assumed this was how it was supposed to work: That the DB abstraction layer enforced it so you didn’t have to have a column constraint - Bohemian

1 Answers

0
votes

I can't comment above (rep isn't high enough), and there's not enough to know that this will answer the question, but Take a look here: https://www.baeldung.com/hibernate-notnull-vs-nullable and https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/appendices/Configurations.html If you have this set, Hibernate will check null before the DB.

spring.jpa.properties.hibernate.check_nullability

So I'm thinking you have that property set.