0

I have created a model with the following field

   @NotNull
    @Column(name = "postal_code")
    private String postalCode;

When I try to post a JSON without the postal code, It should not be saved to the database. That's the reason I have used @NotNull annotation, But to my surprise, It's saving to the database even though the postal code is empty.

So then, I used

@Column(name="postal_code" , nullable=false) //instead of @NotNull

By changing the code as shown in the above, It's not saving to the database with an empty postal code.

My question is why it's not working with @NotNull and what is the diff b/w @NotNull and nullable

ark
  • 3,707
  • 5
  • 21
  • 36
  • Do you have Hibernate Validator or another Bean Validation framework on your classpath? It sounds like the bean validation integration that modifies the domain model at bootstrap isn't happening. – Naros May 15 '18 at 12:57
  • Yes, I have hibernate validator. That is the reason for that issue? – ark May 15 '18 at 13:20
  • Are you configuring `javax.persistence.validation.mode` anywhere? – Naros May 15 '18 at 13:23
  • No, I didn't configure – ark May 15 '18 at 13:24
  • Perhaps enable debug or trace logging and see whether or not there are any messages logged during startup of Hibernate that might explain why the domain model isn't being modified. – Naros May 15 '18 at 19:33

0 Answers0