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 ?

praveen jain
  • 778
  • 2
  • 8
  • 23
  • 6
    Either set `spring.jpa.database-platform` or `spring.jpa.properties.hibernate.dialect` instead of just `hibernate.dialect`. – M. Deinum Nov 24 '16 at 09:31
  • Possible duplicate of [org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set](http://stackoverflow.com/questions/26548505/org-hibernate-hibernateexception-access-to-dialectresolutioninfo-cannot-be-null) – xenoterracide Mar 21 '17 at 17:13

9 Answers9

74

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

spring.jpa.database=mysql
riorio
  • 6,500
  • 7
  • 47
  • 100
  • 2
    Super saver... I found a lot of answers but I managed to come across this answer, I was lucky... – chrips Jun 13 '19 at 00: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 '20 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 09 '20 at 07:36
  • For SQL Server: spring.jpa.database=SQL_SERVER. It works for me! – Weles Jul 15 '21 at 19:40
  • It doesn't work – saran3h Nov 10 '22 at 13:05
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.

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
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.

NateH06
  • 3,154
  • 7
  • 32
  • 56
0

adding the following after creating the Configuration solve the problem :

configuration.configure("hibernate.cfg.xml");
hsusanoo
  • 774
  • 7
  • 18
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

Ian Newland
  • 1,574
  • 1
  • 18
  • 20
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.

JavaDevOps
  • 41
  • 1
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

Caffeine Coder
  • 948
  • 14
  • 17
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)

Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35
0

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

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27