As the title says, what exceptions get thrown under these conditions below on my persisted java class:
@Column(name = "USERNAME", nullable=false, unique=true)
private String username;
@Column(name = "PASSWORD")
@NotNull
@Size(min = 5, max = 25)
private String password;
What is the difference between using @NotNull and @Column(nullable=false)?
i could not find any api docs explaining this along with the type of exception that can occur if username is null and not unique. And what gets thrown if password is null, less then chars and more then 25 chars.
javax.persistence.Columnis used to specify the details of the database column. Thenullableattribute is generally only used when generating the table definitions, and not used at runtime for validation.javax.validation.constraints.NotNullis used at runtime to validate the data before persisting it, assuming that a validation provider is enabled and configured. Violations will throw a subclass ofValidationException.No exception will be thrown by the application itself, but if the database’s table definitions were generated from these annotations, then some JPA exception will be thrown.
A
ValidationExceptionof some form.