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 
4
  • Which version of hibernate are you on? Commented Nov 4, 2015 at 10:43
  • @GergelyBacso version 4.3.11.Final
    – Djama
    Commented Nov 4, 2015 at 10:47
  • I think you added a space after "org.hibernate.dialect.MySQL5Dialect" ....? I see the blank in the stacktrace "[org.hibernate.dialect.MySQL5Dialect ]"
    – Si mo
    Commented Nov 4, 2015 at 10:57
  • 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 MysqlnnoDBDialect Commented Apr 21, 2023 at 18:03

8 Answers 8

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"
3
  • 2
    yes you are right didn't know this could be a root of an error :). Happy to learn that
    – Djama
    Commented Nov 4, 2015 at 11:15
  • 1
    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. Commented Nov 4, 2015 at 11:58
  • 2
    How could I have had the exact same problem? Heck, 38 of us did. Crazy! Commented Nov 1, 2018 at 13:15
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`
4
  • 7
    Hi, I am using spring boot version 3.0.1 and on removal of the dialect it worked thank you. Commented Jan 3, 2023 at 12:57
  • 2
    Yes, it works after removing the dialect property.
    – dgupta3091
    Commented Mar 22, 2023 at 7:21
  • 1
    Same for me, Spring Boot 3.0.1, removing the dialect works. Commented Mar 27, 2023 at 19:58
  • 1
    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')
    – lemario
    Commented Jul 27, 2023 at 18:58
18

[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

1
  • 3
    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.
    – Kasasira
    Commented May 23, 2023 at 7:31
11

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.

2
  • 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')
    – lemario
    Commented Jul 27, 2023 at 18:56
  • THANKS.... after removing spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect from properties file , its working
    – madhu527
    Commented Sep 24, 2023 at 18:11
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

3
  • Do you have a working example that includes a space at the end of the dialect property ? Commented Jul 9, 2022 at 7:12
  • Thanks, removing the property altogether worked.!
    – dgupta3091
    Commented Mar 22, 2023 at 7:21
  • 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')
    – lemario
    Commented Jul 27, 2023 at 18:57
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

1

My issue is solved after I change

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

to

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
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.

2
  • 2
    Please rephrase to make this more obviously an answer and seem less of a description of your own problem.
    – Yunnosch
    Commented May 9, 2021 at 18:15
  • 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.
    – Venkata
    Commented Sep 19, 2022 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.