Why can not JPA / hibernate map to MySQL blob type?

I got the following error:

Caused by: org.hibernate.HibernateException: Wrong column type in TestTable for column PAYLOAD. Found: blob, expected: tinyblob at org.hibernate.mapping.Table.validateColumns(Table.java:284) at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1174) at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:387) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883) ... 60 more 

Hibernate column complains that it is declared as

 private byte[] messagePayload; @Column(name="PAYLOAD") public byte[] getMessagePayload() { return messagePayload; } public void setMessagePayload(byte[] messagePayload) { this.messagePayload = messagePayload; } 

A table in a MySQL table is declared as a BLOB type. Why doesn't Hibernate want to map it, and why does he insist that I use TINYBLOB?

thanks

+6
source share
2 answers

You can try to explicitly specify the blob type with the columnDefinition attribute. Like this:

 @Column(name="PAYLOAD",columnDefinition="blob") 

Or use the @Lob annotation:

 @Column(name="PAYLOAD") @Lob(type = LobType.BLOB) 
+12
source
 @Column(columnDefinition="blob") 

Not working for me. My specifications: - JPA - Hibernate - MySQL

Decision:

 ALTER TABLE `my_table_name` CHANGE `my_column` `my_column` LONGBLOB default NULL; public MyClass { @Lob @Column(length=100000) private byte[] myBlob; } 
+2
source

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


All Articles