The default size of text fields is 255 characters, but you can switch to more as well as less.
One way to do this is by using the annotation @Column
JPA, specifying the attribute length
. 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 the type VARCHAR
in 255, others in 2000 or 4000 characters.
To store larger text, some databases support types such as TEXT
or CLOB
. In these cases, you can use the annotation @Lob
from JPA. Example:
@Lob @Basic(fetch=LAZY)
@Column(name="REPORT")
private String report;
Remark: the annotation @Basic(fetch=LAZY)
serves that this field is read from the bank only when the method getDescription()
is called. This avoids unnecessary reading of large amounts of data.
Thanks @utluiz, clarified all my doubts!
– John Gomes