@Size vs @Length vs @Column

@Size and @Length are similar which are used to validate the size of a field. The first is a Java-standard annotation and the second is specific to Hibernate. Whereas @Column, is a JPA annotation that we use to control DDL statements.

Example for @Size
This annotation makes the bean independent of JPA and its vendors such as Hibernate

public class Customer {
    ...
    @Size(min = 5, max = 15)
    private String fullName;
    ...
}

Example for @Length
It is Hibernate-specific version of @Size

@Entity
public class Customer {
    …
    @Length(min = 5, max = 15)
    private String fullName;
    …
}

Example for @Column
It is used to indicate specific characteristics of the physical database column.

@Entity
public class Customer {
    …
    @Column(length = 15)
    private String fullName;
    …
}

Hibernate

HIBERNATE, created by Gavin King, known as the best and dominated object/relational persistence (ORM) tool for Java developers (Now also supports .NET). It provides many elegant and innovative ways to simplifies the relational database handling task in Java.

Why O/R mapping?

(1) Productivity:  It helps developers to get rid of writing complex and tedious SQL statement, no more need of JDBC APIs for result set or data handling. It makes developers more concentrate on the business logic and increases the project’s productivity.

(2) Maintainability: It helps reduce the lines of code, makes system more understandable and emphasizes more on business logic rather than persistence work (SQLs). More important, a system with less code is easier to re-factor.

(3) Portability: It abstracts our application away from the underlying SQL database and SQL dialect. Switching to other SQL database requires few changes in Hibernate configuration file (Write once/ Run-anywhere).