Java – @ size, @ length and @ column (length = value)
What is the difference between the validation check of the following three fields?
@Entity public class MyEntity { @Column(name = "MY_FIELD_1",length=13) private String myField1; @Column(name = "MY_FIELD_2") @Size(min = 13,max = 13) private String myField2; @Column(name = "MY_FIELD_3") @Length(min = 13,max = 13) private String myField3; // getter & setter }
I saw the first thing related to DDL The second is for bean validation The third is hibernate authentication
Is that right? What I still don't understand is: when do I need to use which one? When is one of these comments triggered?
Edit: think about the following: consider developing an entity with a string type of length 13 Which of the above methods would you choose? Even better: what questions do you have to ask yourself to find out which one suits you?
Solution
>@ column is a JPA annotation, and the length attribute is used by the schema generation tool to set the associated SQL column length
SO 2 And 3 Bean validation should be used to verify the length of a string I will choose 2 Because it is universal