I am using spring-boot and JPA this is the field i am using for the list
@ElementCollection
@Column(columnDefinition="TEXT")
@CollectionTable(name="general_values")
private List<String> values;
But i am getting Error
Caused by: org.postgresql.util.PSQLException: ERROR: value too long for type character varying(255)
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
However In the database table type of value is showing as text. Since i am using TEXT as a type and in the table column as well it is showing as text but Error is still varying(255).
And the request payload for value field
"values":["45","There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable"]
CodePudding user response:
First, you need to drop the table and then add the length attribute in the column then only you can see the effect.
@ElementCollection
@Column(columnDefinition="TEXT", length = 1000)
@CollectionTable(name="general_values")
private List<String> values;
or else you can use SQL command to modify the length
ALTER TABLE table_name MODIFY column_name varchar(new_length);
CodePudding user response:
To solve this error either you have to create schema again where @Column contains length property or you can manually update the table in the database.
@Column(columnDefinition="TEXT", length = 1000)
private List<String> values;
It will create a column with a size of 1000 characters when the schema is generated. There will be no effect on the existing table.
CodePudding user response:
By default maximum characters you can store is 255. Try this
@ElementCollection
@Column(columnDefinition="TEXT", length = 2048)
@CollectionTable(name="general_values")
private List<String> values;
