Entities generated by Hibernate Tools fail hbm2ddl validation: schema-validation: wrong column type encountered in column found [mediumtext (Types#LONGVARCHAR)], but expecting [longtext (Types#VARCHAR)]

using hibernate.hbm2ddl.auto property to Validate

model generated
// Generated Apr 9, 2018 4:54:27 PM by Hibernate Tools 5.2.8.Final
using lastest mysq connector mysql-connector-java-5.1.46.jar

image

it generates this annotation for field descripcion
@Column(name = "descripcion", length = 16777215)

table is

CREATE TABLE `deposito_cajas_compuestas_entrada` (
	`id_caja_entrante` INT(11) UNSIGNED NOT NULL,
	`id_caja_compuesta` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`cantidad` INT(11) UNSIGNED NOT NULL,
	`descripcion` MEDIUMTEXT NULL,
	PRIMARY KEY (`id_caja_compuesta`, `id_caja_entrante`),
	INDEX `id_caja_entrante` (`id_caja_entrante`) USING BTREE,
	CONSTRAINT `deposito_cajas_compuestas_entrada_ibfk_1` FOREIGN KEY (`id_caja_entrante`) REFERENCES `deposito_caja_entrante` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=14
;

mysql -V:
mysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper

when trying to create the EMF i get this error

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [descripcion] in table [deposito_cajas_compuestas_entrada]; found [mediumtext (Types#LONGVARCHAR)], but expecting [longtext (Types#VARCHAR)]

It could be that Hibernate Tools generated the description column like this:

registerColumnType( Types.CLOB, 16777215, "mediumtext" );

while the MySQLDialect maps it like this:

registerColumnType( Types.CLOB, "longtext" );

However, this change occurred in Hibernate 3.3.0. For more details, check out the HHH-2669 Jira issue.

You should debug Hibernate Tools and check why it generates that column as mediumtext.

what should i manually write in the entity to pass validation? is there a mapping in the docs for each mysql type thei i could check?

You can extend the Dialect and override the Types.CLOB like this:

registerColumnType( Types.CLOB, 16777215, "mediumtext" );

as i see its commented in the original file,

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/dialect/MySQL5Dialect.java

what dialect do you recommend me to use, i having similar errors with the mysql57dialect too. as it extends the previous… tis logical

Extend the 57 Dialect and add that call I told you.

ok thanks a lot! nice to meet u again

You are very welcome