Portable serializable objects in sleep mode

I am trying to save objects containing several large types of Serializable . I want Hibernate to automatically generate my DDL (using Hibernate annotations). For the most part, this works, but the default database column type used by Hibernate when saving these types is tinyblob . Unfortunately, this crashes when trying to save my class, because these types will not match the tinyblob length.

However, if I manually configure the type (using @Column(columnDefinition="longblob") or the more portable @Column(length=500000) ), it works fine. Is there a way to make the default binary type longblob instead of tinyblob , so I don’t have to manually specify the @Column annotation for each field?

ExampleClass.java:

 public class ExampleClass { @Column(columnDefinition="longblob") ExampleSerializable ser1; @Column(columnDefinition="longblob") ExampleSerializable ser2; ... } 

ExampleSerializable.java:

 public class ExampleSerializable implements java.io.Serializable { // MANY Fields } 

EDIT

Since there is some confusion: annotating each field with @Column(columnDefinition="longblob") (or more portable: @Column(length=500000) ) already works. I am looking for a solution that does not require me to annotate each field.

+4
source share
1 answer

I think (not tested) that Hibernate will generate a tinyblob, blob, mediumblob column depending on the length of the column (255, 65535, 16777215, respectively), which by default is 255. I would try to specify it (and this would be a portable solution).

Now, if you really want to force something, you will have to expand the MySQL dialogs (but this will hurt portability).

+3
source

Source: https://habr.com/ru/post/1313102/


All Articles