26

I am getting exception even after setting hibernate.dialect property. I am using hibernate 5.0.11 with spring boot 1.4.2 and mysql version as 5.7

application.properties is like this

# Hibernate
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=validate

pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

What is issue here ?

2

9 Answers 9

74

Adding the following line to the properties file solve this problem when I had that error.

spring.jpa.database=mysql
5
  • 2
    Super saver... I found a lot of answers but I managed to come across this answer, I was lucky...
    – chrips
    Jun 13, 2019 at 0:51
  • 2
    I am also facing the same issue post upgrading spring-boot-starter-parent version from 2.1.3.RELEASE to 2.2.5.RELEASE, tried all above options but no luck. I am using spring boot and Hikari to connect to MS SQL Server.
    – Narendra
    Mar 17, 2020 at 18:59
  • Great, it works for me, as we use oracle database, so "spring.jpa.database=oracle" works fine for me.
    – Zi Sang
    Jul 9, 2020 at 7:36
  • For SQL Server: spring.jpa.database=SQL_SERVER. It works for me!
    – Weles
    Jul 15, 2021 at 19:40
  • It doesn't work
    – saran3h
    Nov 10, 2022 at 13:05
2

I also just had a similar issue, but realized I hadn't customized the DB name field properly from copy and pasting into the application.properties file created from Springboot's tutorial:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword

Be sure to replace db_example springuser and ThePassword with your actual values.

Just a "duh" moment for myself, but may be of some use to others.

2

Probably you already solved this, but I had a similar issue.

Adding explicit runtime dependency to mysql should solve the problem:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

That allows spring boot to auto-configure jdbc related beans based on classpath.

1
  • Unfortunately, that did not prevent the dialect resolution error.
    – chrips
    Jun 13, 2019 at 0:50
0

adding the following after creating the Configuration solve the problem :

configuration.configure("hibernate.cfg.xml");
0

I was blatantly missing:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

Also this post has some helpful tips: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

0

In my case, I started my spring boot application with the database excluded:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})

Then once I started creating JPA classes I got an error which I tried to fix with:

@Bean(name = "entityManagerFactory")
public LocalSessionFactoryBean sessionFactory() {
    return new LocalSessionFactoryBean();
}

This led to the exception mentioned in the question.

So the solution was simply to remove DataSourceAutoConfiguration.class from the @SpringBootApplication annotation of course, but it took some time before I noticed the error.

0

I faced the same issue with my Spring boot project upon connecting to an Oracle database.

These are the following steps I performed to troubleshoot-

  1. Make sure relevant hibernate properties are present in application.properties file hibernate.dialect=org.hibernate.dialect.Oracle12cDialect,

    spring.jpa.hibernate.ddl-auto=update

    the dialect depends on which datbase you are using. Also the hibernate.ddl-auto can be one of the 5 properties.

  2. Verify the JDBC url. For e.g. connection string for oracle is like jdbc:oracle:thin:@10.10.32.20:1521/SRV_LICENSING_D1

  3. Verify the database credentials.

  4. Make sure the service name used is in upper case in your property file. Because hibernate is case sensitive. For e.g. service name in case of oracle would be something like SRV_LICENSING_D1

2
  • none of these work
    – saran3h
    Nov 10, 2022 at 12:56
  • can you please post the files you are using: application.propoerties and JDBC url along with service name Nov 10, 2022 at 14:33
0

Reason: Database connection is not satisfied while dialects for db, which database is not important.

Solution: Correct connection string in application.properties (or where is it)

0

In my case the problem was the access modifier to my custom DialectResolver. It was not public.. Rookie mistake :)

Your Answer

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

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