Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] as strategy [org.hibernate.dialect.Dialect]
Asked Answered
E

8

37

I am new in Spring Application with Gradle. Running my project to create the database objects based on my classes created, i got the following error:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] as strategy [org.hibernate.dialect.Dialect]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:960)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:749)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
at com.krypton.smartImmo.SmartImmoApplication.main(SmartImmoApplication.java:10)

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] as strategy [org.hibernate.dialect.Dialect]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:128)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:155)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:136)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:78)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:68)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:165)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)

in the application.properties i ahve the following setting concerning hibernate

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect 
Eadith answered 4/11, 2015 at 10:34 Comment(4)
Which version of hibernate are you on?Foregather
@GergelyBacso version 4.3.11.FinalEadith
I think you added a space after "org.hibernate.dialect.MySQL5Dialect" ....? I see the blank in the stacktrace "[org.hibernate.dialect.MySQL5Dialect ]"Cruz
I just wish to note it here that I was facing the same issue and my issue was not because of spacing or anything as such, my issue got resolved when I used MySQL8Dialect instead of MysqlnnoDBDialectPallet
F
80

Since you errormessage contains that suspicious extra space at the end:

Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ]

I will take a wild guess that you have an extra space at the end of your dialect property.

So look for

"org.hibernate.dialect.MySQL5Dialect "

and change it to:

"org.hibernate.dialect.MySQL5Dialect"
Foregather answered 4/11, 2015 at 11:0 Comment(3)
yes you are right didn't know this could be a root of an error :). Happy to learn thatEadith
The most common mistakes are normally either using a dialect that is not added to that specific hibernate release yet, or funny typos mostly with upper-case/lower-case letter mistakes.Foregather
How could I have had the exact same problem? Heck, 38 of us did. Crazy!Serous
W
25

I also faced the same issue, no need to declare any dialect in the properties file, after removing dialect properties, it work's fine.

My dependencies:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.7</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.7</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Application properties: enter image description here

spring.datasource.name =test
spring.datasource.url=jdbc:mysql://localhost:3306/myDB
spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.jpa.properties.hibernate.dialect=org.hibernate.deialect.MySql5InnoDBDialect
#spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
#spring.jpa.properties.hibernate.dialect=org.hibernate.deialect.MySql55Dialect
spring.datasource.hikari.maximum-pool-size=10
##spring.jpa.hibernate.ddl-auto=updates`
Whiff answered 1/5, 2022 at 8:16 Comment(4)
Hi, I am using spring boot version 3.0.1 and on removal of the dialect it worked thank you.Pallium
Yes, it works after removing the dialect property.Howlet
Same for me, Spring Boot 3.0.1, removing the dialect works.Falcate
I am using version 3.1.0 and I get: Unable to determine Dialect without JDBC metadata (please set 'javax.persistence.jdbc.url', 'hibernate.connection.url', or 'hibernate.dialect')Yiyid
B
17

[Solved 2023] I am using MySQL'8' so I simply changed it to MySQL8Dialect

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

So please check your MySQL Version and it will work fine

Buhrstone answered 14/1, 2023 at 5:27 Comment(1)
First of all thank you for your answer. It saved me when I was about to give up on the error. Since org.hibernate.dialect.MySQL8Dialect was deprecated, I advise you to update it to org.hibernate.dialect.MySQLDialect.Viscid
H
8

If you are using spring boot version above than 3.0.1, then please remove the dialect configuration from your application.properties file altogether. Spring boot does it for you.

Howlet answered 22/3, 2023 at 7:20 Comment(2)
I am using version 3.1.0 and I get: Unable to determine Dialect without JDBC metadata (please set 'javax.persistence.jdbc.url', 'hibernate.connection.url', or 'hibernate.dialect')Yiyid
THANKS.... after removing spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect from properties file , its workingDeparture
S
5

Actually space is not the problem if your dialect name is correct. But as Rajiv Mishra said, you don't need to explicitly specify the dialect, springboot does it for you automatically.

I am using STS ide for this. enter image description here

Spin answered 8/7, 2022 at 7:3 Comment(3)
Do you have a working example that includes a space at the end of the dialect property ?Bushwhacker
Thanks, removing the property altogether worked.!Howlet
I am using version 3.1.0 and I get: Unable to determine Dialect without JDBC metadata (please set 'javax.persistence.jdbc.url', 'hibernate.connection.url', or 'hibernate.dialect')Yiyid
B
3

My MySQL version was 8.1 so I tried org.hibernate.dialect.MySQL8Dialect it worked but MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead

Blackmarketeer answered 5/9, 2023 at 1:53 Comment(0)
T
0

Thanks! I too had the same problem of extra space. Just we have to make sure that, whenever we click on different lines in app.properties file , the cursor should be at the end ,just beside letter t of MySQL8Dialect.Enclose the value for the key spring.jpa.properties.hibernate.dialect with " " quotes and then remove it, that way I had to resolve the issue, as cursor was not coming just after the letter t.

Teem answered 9/5, 2021 at 7:14 Comment(2)
Please rephrase to make this more obviously an answer and seem less of a description of your own problem.Disseise
I too had the same problem with the dialect org.hibernate.dialect.MySQL8Dialect and I replaced it with org.hibernate.dialect.MySQLDialect. It is working now for me. Venkat.Intermezzo
S
0

My issue is solved after I change

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

to

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
Shaina answered 2/4 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.