Hibernate NotNull vs Column(nullable = false)Both of them essentially prevent storing null values in the underlying database, there are significant differences between these two approaches.
The @NotNull annotation is defined in the Bean Validation specification. This means its usage isn't limited only to the entities. On the contrary, we can use @NotNull on any other bean as well
to disable this Hibernate feature, all we need to do is to set hibernate.validator.apply_to_ddl property to false.
The @Column annotation is defined as a part of the Java Persistence API specification.
It's used mainly in the DDL schema metadata generation. This means that if we let Hibernate generate the database schema automatically, it applies the not null constraint to the particular database column.
Hibernate, however, is able to perform the validation of the entity against the possible null values, even if the corresponding field is annotated only with @Column(nullable = false).
In order to activate this Hibernate feature, we need to explicitly set the hibernate.check_nullability property to true:
As a rule of thumb, we should prefer the @NotNull annotation over the @Column(nullable = false) annotation. This way, we make sure the validation takes place before Hibernate sends any insert or update SQL queries to the database.
Also, it's usually better to rely on the standard rules defined in the Bean Validation, rather than letting the database handle the validation logic.