Reputation: 12481
Of the three options, should I be using one or two or all three combined to prevent null values?
@NotNull
@Column(name = "SOME_VALUE", nullable = false)
@Basic(optional = false)
private String someValue;
Note that I don't consider this a duplicate of an existing question. I see many questions that ask about a subset of these three options but have yet to find one that asks about which of the three is appropriate to use in a modern JPA/Hibernate stack.
Upvotes: 5
Views: 2394
Reputation: 8086
@NotNull
javax.validation.constraints
package. Is handled by validation engine(VE).
If a property is not set(or set to null), while persisting, VE throws an exception.
As property validation is handled by a VE, useful in non-persistence layers such as UI layer(JSF).
@Basic(optional=false)
javax.persistence
package.@Column(nullable=false)
javax.persistence
package.Upvotes: 6