Data truncation on longblob field
I get the error SQLError: 1406 Data truncation: Data to long for column 'fileBuffer' ... when i try to insert more than 255 bytes in a longblob column.
The column fileBuffer has longblob data type.
I am using the mysql connector for java ver. 5.1.46 and my mysql server is
Ver 14.14 Distrib 5.7.21, for osx10.13.
The table that has the problem has been created by hibernate
The creation statement is:
CREATE TABLE `FileData` (
`id` int(11) NOT NULL,
`descrSize` varchar(255) DEFAULT NULL,
`errorRecords` int(11) NOT NULL,
`fileName` varchar(255) DEFAULT NULL,
`importedRecords` int(11) NOT NULL,
`loadedTs` tinyblob,
`totRecords` int(11) NOT NULL,
`ente_id` int(11) NOT NULL,
`utente_id` int(11) NOT NULL,
`fileBuffer` longblob,
PRIMARY KEY (`id`),
KEY `FKsf2ufvp5e3p5vv3ax7krmlwd4` (`ente_id`),
KEY `FKf2p7052rcbaw2k309ma2xp2t8` (`utente_id`),
CONSTRAINT `FKf2p7052rcbaw2k309ma2xp2t8` FOREIGN KEY (`utente_id`) REFERENCES `Utente` (`id`),
CONSTRAINT `FKsf2ufvp5e3p5vv3ax7krmlwd4` FOREIGN KEY (`ente_id`) REFERENCES `Ente` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
This is the java code that inserts the blob:
FileData fd = new FileData(); //this is a Hibernate entity
...
fbuffer = new byte[256];
Blob blob = Hibernate.getLobCreator(jpaApi.em().unwrap(org.hibernate.Session.class)).createBlob(fbuffer);
fd.setFileBuffer(blob);
...
jpaApi.em().persist(fd);
when the transaction commit i get the error.
if filebuffer is less then 256 bytes it works without errors
thanks in advance