5

The interesting thing is that in the entity:

public static final int maxContentSize = 2097152; //2Mb
@Lob
@Column(length=maxContentSize)
private byte[] content;
@Column(length = 100)
private String mimetype;
@Column(length = 50)
private String fileName;

However, some files (65-70k size) are inserted OK, but most of them get the error:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'CONTENT' at row 1

I've checked, before creating the entities, the sizes are correct.

csaadaam
  • 103
  • 1
  • 3
  • 8
  • 1
    And what is the schema definition for that table ? I don't mean what are these JPA annotations ... what is it actually? – DataNucleus Apr 26 '12 at 08:00

1 Answers1

7

According to JPA doc "length" is only used for String properties.

(Optional) The column length. (Applies only if a string-valued column is used.)

If you are automatically generating your DDL using a tool.. you can use "columnDefinition" attribute

@Column(columnDefinition = "LONGBLOB") 
private byte[] content;
vinodn
  • 366
  • 3
  • 10
  • 1
    Wow. It was based on this answer: http://stackoverflow.com/questions/3503841/jpa-mysql-blob-returns-data-too-long/3507664#3507664 but actually it is a blob column, the working files are <65536 bytes... – csaadaam Apr 26 '12 at 08:47
  • right now it is automatically generated, but I've just known that we will be using oracle db and we'll have the schema definitions written. so right now I'll just alter the column to really be medium/longblob – csaadaam Apr 26 '12 at 08:52