The default length of text fields is 255 characters, but you can change to more, as well as less.
One way to do this is by using the @Column
annotation JPA, specifying the length
attribute. Example:
@Column(name="DESC", nullable=false, length=512)
private String description;
However, text fields will always have a limit, but not from Hibernate, but from the database itself.
Some databases limit fields of type VARCHAR
to 255, others in 2000 or 4000 characters.
To store larger text, some banks support types such as TEXT
or CLOB
. In these cases, you can use the @Lob
annotation of the JPA. Example:
@Lob @Basic(fetch=LAZY)
@Column(name="REPORT")
private String report;
Note: The @Basic(fetch=LAZY)
annotation serves to read this field from the database only when the getDescription()
method is called. This prevents unnecessary reading of large amounts of data.