Issue
I received an exception when starting the application:
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MySQL8Dialect] as strategy [org.hibernate.dialect.Dialect]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:126)
I am using MySQL 8.0.
pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
hibernate.cfg.xml:
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/botdb?serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.useSSL">false</property>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
Solution
According pom.xml you are currently using Hibernate 5.2.12. From 5.2 Javadocs one can see that it does not have MySQL8Dialect
.
MySQL8Dialect was introduced in Hibernate 5.3 (see Javadoc). Problem can be solved by updating to Hibernate to 5.3 or to 5.4.
If updating Hibernate is not an option, then one must create custom dialect. That can be as easy as simply copying MySQL8Dialect.java
from newer version to your code base and referencing it from persistence.xml. Potentially minor modifications are necessary.
Answered By - Mikko Maunu
Answer Checked By - Willingham (JavaFixing Volunteer)