While migrating my project to springboot 3.1.0 with hibernate 6.2.2 and mysql-connector-j 8.0.33 , I am getting an error :Unable to resolve name [org.hibernate.dialect.MySQLInnoDBDialect] as strategy [org.hibernate.dialect.Dialect]
Hibernate dialect used is org.hibernate.dialect.MySQL8Dialect
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan(“com.project.entites”);
Properties jpaProperties = new Properties();
jpaProperties.setProperty(“hibernate.hbm2ddl.auto”, “none”);
jpaProperties.setProperty(“hibernate.show_sql”, “true”);
jpaProperties.setProperty(“hibernate.dialect”, “org.hibernate.dialect.MySQL8Dialect”);
factory.setJpaProperties(jpaProperties);
return factory;
}
Full stack trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘projectConf’ defined in class path resource [com/demo/project/ProjectAutoConfiguration.class]: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: Unable to resolve name [org.hibernate.dialect.MySQLInnoDBDialect] as strategy [org.hibernate.dialect.Dialect]\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)\r\n\tat org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1156)\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:931)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:733)\r\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:435)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:311)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1305)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1294)\r\n\tat i
Since Hibernate 6, version-specific dialects were deprecated in favour of automatic database version discovery. You should just use the standard org.hibernate.dialect.MySQLDialect
dialect.
See also the Hibernate 6 migration guide chapter about dialects.
2 Likes
I am getting below error while using MySQLDialect
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.MySQLDialect ]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:123) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:150) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
… 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.MySQLDialect
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:215) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:120) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
… 40 common frames omitted
Caused by: java.lang.Throwable: null
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:208) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
… 45 common frames omitted
Suppressed: java.lang.ClassNotFoundException: org.hibernate.dialect.MySQLDialect
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:205) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
… 45 common frames omitted
Suppressed: java.lang.ClassNotFoundException: org.hibernate.dialect.MySQLDialect
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:205) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
… 45 common frames omitted
Suppressed: java.lang.ClassNotFoundException: org.hibernate.dialect.MySQLDialect
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:205) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
… 45 common frames omitted
That’s weird, looks like a class loading issue on your side. I can confirm that the class name and package you’re trying to use are correct.
Hi @lovinjv , I am also facing same error with MySQLInnoDBDialect and MySqlDialect, when migrating hibernate from 5 to 6.5.2.Final version, Can you please tell me how did you resolve this error?Thank you.