In my JPA entity classes, fields are mapped to table columns with declarations such as
@ManyToOne(optional = false)
@JoinColumn(name = "user_id")
private User user;
In my case, I never generate the database schema from the entity classes (I use hand-written DDL files that are applied automatically by Flyway on startup).
Given this, is there any reason why I should specify the optional of @ManyToOne? If they're only relevant when the schema is generated from the entity classes, then it seems better to remove them as this leaves us with a single "source of truth" about the schema (the DDL files or the database itself).
If on the other hand, these attributes affect the validation that is performed when an entity is persisted, then I guess I can't remove them.
I checked the javadocs for this attribute, but it's pretty light of details
(Optional) Whether the association is optional. If set to false then a non-null relationship must always exist.