[CONJ-893] DatabaseMetaData.getColumns regression causing TINYINT(x) with x > 1 to return BIT type in place of TINYINT Created: 2021-07-20  Updated: 2021-07-26  Resolved: 2021-07-26

Status: Closed
Project: MariaDB Connector/J
Component/s: metadata
Affects Version/s: 2.7.3
Fix Version/s: 2.7.4

Type: Bug Priority: Major
Reporter: member sound Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

spring-boot-2.5.2


Attachments: Zip Archive mariadb-test.zip    

 Description   

Sidenote: I don't know exactly is this is an issue of hibernate or mariadb-java-client.
But the issue occurs as soon as mariadb-java-client is upgraded from 2.7.2 to 2.7.3, thus there must have been a breaking change inside?

Precondition: create a mariadb or mysql table as follows:

CREATE TABLE example (
 id bigint NOT NULL AUTO_INCREMENT,
 foo tinyint DEFAULT NULL,
 PRIMARY KEY (id)
);

With entity class:

@Entity
public class Example {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public long id;
 
	@Column(columnDefinition = "TINYINT")
	public Integer foo;
}

Run the application attached. The application runs and terminates without errors.

Now the interesting part: upgrade the mariadb version in `pom.xml` to:

<mariadb.version>2.7.3</mariadb.version>

(which is the natively shipped version in `spring-boot-2.5.2`).

Result: the startup validation fails:

2021-07-20 13:54:19.107 ERROR 66260 --- [           main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [foo] in table [example]; found [bit (Types#TINYINT)], but expecting [tinyint (Types#INTEGER)]
2021-07-20 13:54:19.108  WARN 66260 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [foo] in table [example]; found [bit (Types#TINYINT)], but expecting [tinyint (Types#INTEGER)]

This means `mariadb-2.7.3` must have introduced a change that causes this error. But I could not find any hint on this inside the changelogs. Please have a look.



 Comments   
Comment by Diego Dupin [ 2021-07-26 ]

There has been a regression in 2.7.3
recent MySQL 8.0 version now has changed metadata : INFORMATION_SCHEMA.COLUMNS now sometime doesn't return `tinyint` with x for size, but `tinyint`. Support of this change has cause this regression.

Generated at Thu Feb 08 03:19:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.