sexta-feira, 3 de janeiro de 2020

Java Error (Data too long) - JPA mapping




 WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1406, SQLState: 22001
 ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Data truncation: Data too long for column 'document' at row 1


In general when we need to map a data be it a JPG, PDF etc. we use "byte [] document". Although it is quite common to find a problem where the data is very large. Soon JPA mapping problems emerge.

TINYBLOB: maximum length of 255 bytes
BLOB: maximum length of 65,535 bytes
MEDIUMBLOB: maximum length of 16,777,215 bytes
LONGBLOB: maximum length of 4,294,967,295 bytes


One solution is to use the @lob annotation from hibernate.


@Lob
@Column(name="document",columnDefinition="BLOB")
private byte[] document;

Nenhum comentário:

Postar um comentário