Unknown Guy
Unknown Guy

Reputation: 137

value too long for type character varying(255) for length 100000

I am using Spring Data JPA and my column definition is

@Column(length = 100000)
private String description;

And in the payload, I am using description having character count 20000. But its still throwing

ERROR: value too long for type character varying(255)`

If 100000 is not enough to hold character of length 20000 how is the error varying(255) however in the physical database table I can see character varying(100000) in table definition. database column

Getting same error even for the Text Type using text of length 1990 only

   2021-08-23 17:48:24.727  WARN 21044 --- [nio-8089-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 22001
   2021-08-23 17:48:24.727 ERROR 21044 --- [nio-8089-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: value too long for type character varying(255)
   2021-08-23 17:48:24.733 ERROR 21044 --- [nio-8089-exec-3] org.hibernate.AssertionFailure           : HHH000099: an assertion failure occurred

Upvotes: 2

Views: 20202

Answers (2)

Sure, your java code run an sql statement where an varchar(255) column is overupdated with more than 255 length string.

  • Perhaps you use Hibernate Envers
  • Perhaps there is some trigger function on the table
  • Perhaps you is connected other db
  • Perhaps others

First log the sql statement with values.

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

https://www.baeldung.com/sql-logging-spring-boot

You could run the sql statement to your db.

  • If works than you connect other db
  • If not, then you can solve problem on db side.

Upvotes: 2

NTIC TECH
NTIC TECH

Reputation: 116

The problem is on the database because the varchar column in PostgreSQL db as i know accept 255 char, change the character varying or character column to be a text column type instead (Since Postgres 9.2, sometimes text is not used initially)

ALTER TABLE your_table ALTER COLUMN description TYPE text;

Upvotes: -1

Related Questions