Why cant JPA/hibernate map to MySQL blob type?

hibernate blob stream
jpa blob stream
lob string jpa
jpa serialize object to blob
lob postgres hibernate
hibernate longtext annotation
hibernate lob helper
hibernate 5 @lob

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

The column hibernate is complaining about is declared as

private byte[]  messagePayload;

public byte[] getMessagePayload() {
        return messagePayload;

public void setMessagePayload(byte[] messagePayload) {
 this.messagePayload = messagePayload;

The table in the MySQL table is declared as a BLOB type. Why doesnt Hibernate want to map to it and why does it insist that i use TINYBLOB?


You could try to set explicitly the type blob with columnDefinition attribute. Like this:


Or use the @Lob annotation:

@Lob(type = LobType.BLOB)

Hibernate Binary Data and BLOB Mapping Example, Hibernate examples for mapping primitive byte array and java.sql.Blob Blob) of Java type to database type using Hibernate ORM framework. We are going to code an example program that works with a MySQL database. Test cases we dont want. we want actual implementation right from controller,  Introduction. In this article, we are going to see how to map the Oracle JSON column storage types when using JPA and Hibernate. My hibernate-types project has long been supporting JSON for PostgreSQL and MySQL.


Did not work for me. My specifications: - JPA - Hibernate - MySQL


ALTER TABLE `my_table_name` CHANGE `my_column` `my_column` LONGBLOB default NULL;

public MyClass {
   private byte[] myBlob;

Mapping BLOBs and CLOBs with Hibernate and JPA, JPA and Hibernate provide two kinds of mappings for these types. You can We will map the cover column as BLOB and the content column as a CLOB. You can not only use it with Hibernate but also with EclipseLink and OpenJPA. @Lob annotation is used to map fields/properties of large value to a corresponding database-supported large object type. A Lob may be either a binary or character type. The Lob annotation may be used in conjunction with the @Basic annotation. It can also be used with @ElementCollection, if annotated on the collection of basic type. Example

I've tried this solution:

public class MySqlCustomDialect extends org.hibernate.dialect.MySQLDialect{

    public MySqlCustomDialect() {


        this.registerColumnType(-4, "blob");
        this.registerColumnType(-3, "blob");
        this.registerColumnType(-3, 16777215L, "blob");
        this.registerColumnType(-3, 65535L, "blob");
        this.registerColumnType(-3, 255L, "blob");
        this.registerColumnType(2004, "blob");


This way, I've overridden the original value for ColumnType defined in MySqlDialect. It works only is BLOB is defined as column type in MySQL. I've experienced a side effect trying to alter column type to LONGBLOB, as expected:

[longblob (Types#LONGVARBINARY)], but expecting [blob (Types#BLOB)]

Just for previous re-configuration.

Mapping LOB Data in Hibernate, Learn how to map Large Object Data using Hibernate's @Lob annotation. understands it should store the “photo” property as BLOB data type. back from the database and using Hibernate to map it back to Java object to  When you prepare a Hibernate mapping document, you find that you map the Java data types into RDBMS data types. The types declared and used in the mapping files are not Java data types; they are not SQL database types either. These types are called Hibernate mapping types, which can translate from Java to SQL data types and vice versa.

Hello this works for me.

@Column(name = "CH_VAL_MODIFIEES")
private String valeurModifiee;

In my dataBase, I have a CH_VAL_MODIFIEES created with LONGTEXT DataType.

Hibernate Binary Data and BLOB Mapping example, In this video you will learn about Binary Data and BLOB Mapping example in hibernate. Below Duration: 13:19 Posted: Nov 17, 2017 We successfully built a Restful CRUD API using Spring Boot, Mysql, Jpa and Hibernate. You can find the source code for this tutorial on my github repository . Feel free to clone the repository and build upon it.

Mapping BLOBs & CLOBs with JPA and Hibernate, You will learn how to map these database columns to a String or a byte[] and how to . now by Duration: 10:05 Posted: Sep 3, 2019 11. what type should I use ? long Binary ?? forum.hibernate.org. It depends upon the JDBC types that MySQL maps those DB type to. To check this, obtain a jdbc connection and do the following connection.getMetaData().getTypeInfo() This will return you a ResultSet where each row describes a SQL type in the underlying database.

Mapping Oracle JSON columns with JPA and Hibernate, How to map Oracle JSON columns using JPA and Hibernate If the JSON document doesn't exceed 4000 bytes, then it's better to For large JSON documents, BLOB is preferred over CLOB because The JsonStringType is the same Hibernate Type we previously used for MySQL, and it's being offered  @vlad_mihalcea I have seen a few articles on the matter but curious of your thoughts on hibernate mapping of postgres enum data type. — Chris Whited (@cmwhited) September 7, 2017. In this article, we are going to see how various ways to map an Enum using JPA and Hibernate. Domain Model. Considering we have the following entity:

How to read data from BLOB using JPA (Hibernate), The table in the MySQL table is declared as a BLOB type. Why doesnt Hibernate want to map to it and why does it insist that i use TINYBLOB? I found particularly when working with Hibernate 3 to store and retrieve BLOB objects we need certain things to be taken care of. Let us see a tutorial where we will using Spring 3 MVC and Hibernate 3 to store and retrieve blob objects in database. Our Goal Our goal is to create a Document Manager application in Spring 3 MVC and Hibernate.

  • columnDefinition is not portable, later is standard. type is available in hibernate while it isn't in JPA.
  • I have done the second with EclipseLink and MySQL and can verify that it works as expected.
  • I have added comment for more information to the answer as OP has mentioned tags JPA/Hibernate, not about its working.
  • Where is your @Lob annotation coming from? The JPA one doesn't seem to have a type argument.