Uhm, I have a question regarding the @Basic(optional = false) and @NotNull notation.
Usually, we would write variables in entity class as below:
Mock-up code:
@Basic(optional = false)
@NotNull
@Column(name = USERNAME)
private String userName;
The notation above describes that for the field username , it would not accept a NULL value.
Usually, the @Basic(optional = false) notation is followed by @NotNull notation , but if I would like to have a field, let's say userID , and it is an Auto-Increment type , which is also the Primary Key , should I just wrote the code as below?
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = USERID)
private Integer userID;
Or remove the @Basic(optional = false) as well?
Edited
Latest code:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = USERID)
private Integer userID;
One more question, is that only @Basic(optional = false) will work same as @Basic(optional = false) followed-up by @NotNull ?
Code shown as below:
Code 1
@Basic(optional = false)
@NotNull
@Column(name = USERNAME)
private String userName;
Code 2
@Basic(optional = false)
@Column(name = USERNAME)
private String userName;