The most recent versions of hibernate JPA provider applies the bean validation constraints (JSR 303) like @NotNull
to DDL by default (thanks to hibernate.validator.apply_to_ddl property
defaults to true
). But there is no guarantee that other JPA providers do or even have the ability to do that.
You should use bean validation annotations like @NotNull
to ensure, that bean properties are set to a none-null value, when validating java beans in the JVM (this has nothing to do with database constraints, but in most situations should correspond to them).
You should additionally use the JPA annotation like @Column(nullable = false)
to give the jpa provider hints to generate the right DDL for creating table columns with the database constraints you want. If you can or want to rely on a JPA provider like Hibernate, which applies the bean validation constraints to DDL by default, then you can omit them.