skip to Main Content

I have a text field in my Hibernate entity as shown below:

@Column(nullable = false, columnDefinition = "TEXT")
private String content;

So, what is the default and suggested length for this field (it is a content of a blog)? And should I set it using length as shown below?

@Column(nullable = false, columnDefinition = "TEXT", length = 4000)
private String content;

Note: My database is PostgreSQL.

2

Answers


  1. As documented in the manual the data type text accepts no length limit and has a maximum size of 1GB.

    If you want a constraint to limit the length, use a check constraint on a text column or use the varchar(4000).

    Login or Signup to reply.
  2. Max column length of text type is your RDBMS’s max length for text datatype, in PostgreSQL case is 1Gb. If you want to limit size use

    @Column (columnDefinition = "VARCHAR (n)" ) 
    

    @Column annotation indicates specific characteristics of the physical database column, and will be enforced by database (PostgreSQL checks and throws an error)

    Or

    @column(columndefinition="text")
    

    That will adjust to the limit aforementioned, where length attribute may not work and won’t be necessary.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search