Difference between @Size, @Length and @Column(length=value) when using JPA and Hibernate

前端 未结 1 751
孤城傲影
孤城傲影 2020-12-13 08:37

What is the difference between the validation check of the following three fields?

@Entity
public class MyEntity {

    @Column(name = \"MY_FIELD_1\", length         


        
相关标签:
1条回答
  • 2020-12-13 08:49
    1. @Column is a JPA annotation and the length attribute is used by the schema generation tool to set the associated SQL column length.
    2. @Size is a Bean Validation annotation that validates that the associated String has a value whose length is bounded by the minimum and maximum values.
    3. @Length is a Hibernate-specific annotation and has the same meaning as @Size

    So both 2. and 3. should validate the String length using Bean Validation. I'd pick 2. because it's generic.

    0 讨论(0)
提交回复
热议问题