I am reviewing the code of a colleague. In his entity object he has set nullable = false
and he is also checking in the setter that the value to set is not null
.
Is this useful? In any case, the nullable = false
will throw an exception at some point.
(The checkArgumentNotNull
will throw an illegal argument exception if the value is null
.)
private TypeChampMaterielDefaillant typeChamp;
@Column(name = "TYPE_CHAMP", nullable = false, length = 30)
@Enumerated(EnumType.STRING)
public TypeChampMaterielDefaillant getTypeChamp() {
return typeChamp;
}
public void setTypeChamp(TypeChampMaterielDefaillant typeChamp) {
checkArgumentNotNull(typeChamp, "typeChamp");
this.typeChamp = typeChamp;
}
EDIT
So if I understand correctly nullable=false only apply to schema generation, thus if the database is not generated with the current entity it will be possible to persist a null value