I'm updating my spring-boot dependencies to the latest version (2.6.3) for vulnerability reasons. I'm having a problem with "spring-boot-gradle-plugin" in versions above 2.6.0. When trying to run the application, I get the following error:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table

Downgrading "spring-boot-gradle-plugin" to 2.5.9 works fine.

Here are some parts of my build.gradle related dependencies and my application.properties, respectively:

...
buildscript {
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:2.6.3"
...
dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.6.3'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: '2.6.3'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.6.3'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.6.3'
...
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.url=URL
spring.datasource.username=USERNAME
spring.datasource.password=PASSWORD
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.type=trace
spring.jpa.properties.connection.CharSet=utf8
spring.jpa.properties.connection.characterEncoding=utf8
spring.jpa.properties.hibernate.connection.useUnicode=true
spring.jpa.properties.hibernate.id.new_generator_mappings=false
...

Any ideas on how I can solve this problem in "spring-boot-gradle-plugin" 2.6.x versions?

Comment From: scottfrederick

@Nikofoxxx It appears you are specifying dependency versions explicitly instead of using Spring Boot's dependency management to choose a version for you. If there are other dependencies with versions specified that aren't shown here, it's possible you're using an incompatible set of libraries. We can't be sure with the limited information provided. If you would like us to spend some time investigating, please spend some time providing a complete minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: Nikofoxxx

I'm sorry about the delay, I've made some researches and also was trying to fix the problem.

Please ignore the "spring-boot-gradle-plugin" that I've mentioned above. I've discovered that the problem is related with the spring-boot version 2.6.3, for sure, and the "spring.jpa.database-platform" (dialect) that I'm using.

My database is MySQL, and I was using dialect "org.hibernate.dialect.MySQL5InnoDBDialect". After upgrade the spring-boot to 2.6.3, the error that I mentioned above started to appear.

Another important thing to say, it's that I can't use the MySQL default JDBC, for license reasons. So, I'm using the MariaDB JDBC to connect to my MYSQL database.

After some tests, I figured out that if I comment the dialect line (forcing it to automatically choose the dialect to use) or if I change the dialect to "org.hibernate.dialect.MariaDB103Dialect" (or any MariaDB-Like dialect) all works again. In the "commented line" case, it chooses automatically a MariaDB dialect too.

I think that the problem isn't related with MySQL Dialect + MariaDB JDBC + MySQL database itself, because in older versions of spring boot (<= 2.5.9) this combination worked fine.

So, to test from the beginning, and to make sure that the problem doesn't come from my environment, I've created a Spring Initializr demo project just with the spring boot dependencies and the MariaDB client, and, off course, the dialect as the "org.hibernate.dialect.MySQL5InnoDBDialect":

plugins {
    id 'org.springframework.boot' version '2.6.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.2.4'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}
#Data source
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.url=URL
spring.datasource.username=USERNAME
spring.datasource.password=PASSWORD
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.type=trace

spring.jpa.properties.connection.CharSet=utf8
spring.jpa.properties.connection.characterEncoding=utf8
spring.jpa.properties.hibernate.connection.useUnicode=true
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.datasource.hikari.maximumPoolSize=5

And the problem persists. So, I concluded that the problem is not related with my environment, but with: spring-boot 2.6.3 + MySQL Dialect + MariaDB JDBC + MySQL database.

And obviously, if I roll back the spring-boot version back to 2.5.9 all works again. The problem starts happening from version 2.6.0.

So, for to reproduce this, I suggest you also create a demo project in Spring Initializr with these same specifications.

Thanks a lot!

Comment From: scottfrederick

Thanks for the additional information and taking the time to narrow down the problem.

It's not clear what part Spring Boot is playing in this issue, other than setting up the dialect for Hibernate to use and managing dependency versions. Spring Boot 2.5.9 manages the Hibernate version to 5.4.33 while Boot 2.6.3 uses Hibernate 5.6.4.Final. Can you try running your app with Boot 2.6.3 while overriding Hibernate back to the Boot 2.5.9 managed version? You can do this by adding a line to your build file as shown in the documentation:

ext['hibernate.version'] = '5.4.33.Final'

Comment From: Nikofoxxx

@scottfrederick it gives another error:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/boot/model/naming/CamelCaseToUnderscoresNamingStrategy

Comment From: wilkinsona

That's to be expected as CamelCaseToUnderscoresNamingStrategy is new in Hibernate 5.5. Setting spring.jpa.hibernate.naming.physical-strategy to org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy should help.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.