356

I am trying run a spring-boot application which uses hibernate via spring-jpa, but i am getting this error:

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
        at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
        at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
        at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
        at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550)
        ... 21 more

my pom.xml file is this:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.8.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
       </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
    </dependency>
</dependencies>

my hibernate configuration is that (the dialect configuration is in the last method from this class):

@Configuration
@EnableTransactionManagement
@ComponentScan({ "com.spring.app" })
public class HibernateConfig {

   @Bean
   public LocalSessionFactoryBean sessionFactory() {
      LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();

      sessionFactory.setDataSource(restDataSource());
      sessionFactory.setPackagesToScan(new String[] { "com.spring.app.model" });
      sessionFactory.setHibernateProperties(hibernateProperties());

      return sessionFactory;
   }

   @Bean
   public DataSource restDataSource() {
      BasicDataSource dataSource = new BasicDataSource();

      dataSource.setDriverClassName("org.postgresql.Driver");
      dataSource.setUrl("jdbc:postgresql://localhost:5432/teste?charSet=LATIN1");
      dataSource.setUsername("klebermo");
      dataSource.setPassword("123");

      return dataSource;
   }

   @Bean
   @Autowired
   public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
      HibernateTransactionManager txManager = new HibernateTransactionManager();
      txManager.setSessionFactory(sessionFactory);
      return txManager;
   }

   @Bean
   public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
      return new PersistenceExceptionTranslationPostProcessor();
   }

   Properties hibernateProperties() {
      return new Properties() {
         /**
         * 
         */
        private static final long serialVersionUID = 1L;

        {
            setProperty("hibernate.hbm2ddl.auto", "create");
            setProperty("hibernate.show_sql", "false");
            setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
         }
      };
   }
}

what I am doing wrong here?

Simulant
  • 19,190
  • 8
  • 63
  • 98
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
  • See my solution at https://stackoverflow.com/questions/72296481/spring-boot-hibernate-error-access-to-dialectresolutioninfo-cannot-be-null-when/72309989#72309989 if looking for multiple database support. – pixel May 19 '22 at 19:18

37 Answers37

298

First remove all of your configuration Spring Boot will start it for you.

Make sure you have an application.properties in your classpath and add the following properties.

spring.datasource.url=jdbc:postgresql://localhost:5432/teste?charSet=LATIN1
spring.datasource.username=klebermo
spring.datasource.password=123

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

If you really need access to a SessionFactory and that is basically for the same datasource, then you can do the following (which is also documented here although for XML, not JavaConfig).

@Configuration        
public class HibernateConfig {

    @Bean
    public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
         HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
         factory.setEntityManagerFactory(emf);
         return factory;
    }
}

That way you have both an EntityManagerFactory and a SessionFactory.

UPDATE: As of Hibernate 5 the SessionFactory actually extends the EntityManagerFactory. So to obtain a SessionFactory you can simply cast the EntityManagerFactory to it or use the unwrap method to get one.

public class SomeHibernateRepository {

  @PersistenceUnit
  private EntityManagerFactory emf;

  protected SessionFactory getSessionFactory() {
    return emf.unwrap(SessionFactory.class);
  }

}

Assuming you have a class with a main method with @EnableAutoConfiguration you don't need the @EnableTransactionManagement annotation, as that will be enabled by Spring Boot for you. A basic application class in the com.spring.app package should be enough.

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {


    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

} 

Something like that should be enough to have all your classes (including entities and Spring Data based repositories) detected.

UPDATE: These annotations can be replaced with a single @SpringBootApplication in more recent versions of Spring Boot.

@SpringBootApplication
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
} 

I would also suggest removing the commons-dbcp dependency as that would allow Spring Boot to configure the faster and more robust HikariCP implementation.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • 1
    but is there any way to avoid create this file `application.propertes`? I prefer a way where I do all the configuration in the class HibernateConfig. – Kleber Mota Oct 24 '14 at 13:54
  • 4
    Why? The whole purpose of Spring Boot is that it does auto configuration for you... So you prefer to include a verbose java configuration over 7 lines in a properties file?! – M. Deinum Oct 24 '14 at 13:57
  • 2
    It could even be 6 lines in a property file. You don't need to set spring.datasource.driverClassName when you're using Postgres as Boot will infer it from spring.datasource.url. – Andy Wilkinson Oct 27 '14 at 09:08
  • 1
    application.properties files are a bad way to configure software. You cannot presume there will be a file-system (and you wouldn't want to use it). Bundling it in the .jar or .war means you have deployment specific builds which is a very bad idea. Also, it's insecure since your passwords are on disk. – Alex Worden Sep 12 '15 at 20:39
  • 2
    @AlexWorden No it isn't... Instead of putting random comments you might first want to read how properties are loaded especially the support Spring Boot has. Passwords on disk don't have to be a problem if you set the file rights straight. Putting them in a database isn't much better... – M. Deinum Sep 13 '15 at 10:54
  • I have multiple datasources, which is why i can't autoconfigure (I think). Still looking for solution to this. – AdrianVeidt Sep 22 '15 at 12:04
  • 4
    Instead of using 3 annotations i.e. Configuration,EnableAutoConfiguration,ComponentScan. We can use SpringBootApplication annotation – Pankaj Nov 08 '15 at 18:57
  • 1
    `spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect` was enough for me. – AlikElzin-kilaka Jun 11 '20 at 07:58
  • `org.hibernate.dialect.PostgreSQLDialect `is deprecated, use `org.hibernate.dialect.PostgreSQL82Dialect` instead – 袁文涛 Aug 18 '20 at 05:05
  • Hibernate continues to release updated dialects. See: https://docs.jboss.org/hibernate/orm/current/javadocs/org/hibernate/dialect/package-summary.html – David Siegal Sep 23 '20 at 17:28
  • For Oracle database, spring.jpa.database-platform=org.hibernate.dialect.OracleDialect – Amulya Koppula Jan 18 '22 at 07:52
  • This does not work if you use multiple data sources for databases by different vendors. for example if you have one data source for DB2 and another for Oracle, this will not work. How would you set the dialect in that case? – pixel May 18 '22 at 20:58
264

I was facing a similar problem when starting up the application (using Spring Boot) with the database server down.

Hibernate can determine the correct dialect to use automatically, but in order to do this, it needs a live connection to the database.

mhnagaoka
  • 3,031
  • 1
  • 16
  • 18
  • 2
    My problem was similar to this in that pg_hba.conf on the server wasn't configured for the remote connection, which gave me this error. – Brian Jul 06 '15 at 17:47
  • 27
    If the database you are trying to connect to does not exists you also see this error. – Jonas Pedersen Aug 15 '15 at 18:57
  • 25
    Got the same problem, in my case the DB was up but the credentials were wrong. +1 – Federico Piazza Aug 05 '16 at 17:23
  • surprisingly i started getting this issue when dropped schema expecting hbm2ddl.auto=true will create db and tables. however it failed. but wen i created empty schema hbm2ddl worked creating tables – Saurabh Mar 21 '17 at 00:19
  • IP of database machine has been changed but a DNS was resolving to the old one :-( – Illidan Feb 27 '19 at 12:31
  • Oh man... you saved me. I had changed my password... and that connection issue was enough to create all the errors – chrips May 30 '19 at 18:24
  • 1
    For me as well, DB server was not up and that's why this error came up while deploying the spring boot app. – Dhruvam Gupta Dec 29 '20 at 12:31
  • 4
    Why doesn't it throw a more obvious error first, like "Cannot connect to database" or something? – ADJenks Sep 16 '21 at 22:35
  • The problem with me was just the SQL syntax, it became clear after using a postrgresql editor – Rstar37 May 19 '22 at 18:30
  • 1
    Well, once I corrected the port number in configuration, this error disappeared. – Iceberg Jun 17 '22 at 07:26
69

add spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect in application.properties file

alpine
  • 927
  • 6
  • 17
  • This is a great answer - allows me to use a MockBean for my database class and not have real connection information in my properties profile – Taylor Mar 06 '19 at 19:15
  • Adding spring.jpa.properties.hibernate.dialect to the application.properties helped me. Thank you) – Maks May 07 '20 at 16:13
  • This does not work if you use multiple data sources for databases by different vendors. for example if you have one data source for DB2 and another for Oracle, this will not work. – pixel May 18 '22 at 20:55
  • dialect: org.hibernate.dialect.OracleDialect in my case. – Smart Coder Dec 12 '22 at 16:44
33

I got this error when my database was not created. After creating the DB manually, it worked fine.

ACV
  • 9,964
  • 5
  • 76
  • 81
  • 2
    Normally you can avoid manual creation by using "spring.jpa.hibernate.ddl-auto=create" – Andrei Jan 18 '16 at 01:00
  • @Andrei - how / where would I specify "spring.jpa.hibernate.ddl-auto=create"? – Alex Worden Aug 10 '16 at 19:45
  • 2
    @AlexWorden, Andrei meant you can put it in application.properties if it is Spring Boot. There must be the equivalent for xml based Spring configuration. – ACV Aug 12 '16 at 09:32
  • Does this error appear only when the database does not exist or also when the tables inside the database are not present? – zygimantus Sep 20 '17 at 10:33
  • Only when there is no DB – ACV Sep 20 '17 at 13:58
  • 1
    I had given wrong password and I was facing the same error. Thank you ACV, you helped me a lot. – santu Dec 15 '17 at 10:35
20

I also faced a similar issue. But, it was due to the invalid password provided. Also, I would like to say your code seems to be old-style code using spring. You already mentioned that you are using spring boot, which means most of the things will be auto configured for you. hibernate dialect will be auto selected based on the DB driver available on the classpath along with valid credentials which can be used to test the connection properly. If there is any issue with the connection you will again face the same error. only 3 properties needed in application.properties

# Replace with your connection string
spring.datasource.url=jdbc:mysql://localhost:3306/pdb1

# Replace with your credentials
spring.datasource.username=root
spring.datasource.password=
Pankaj
  • 615
  • 5
  • 9
16

Remove the redundant Hibernate Configuration

If you're using Spring Boot, you don't need to provide the JPA and Hibernate configuration explicitly, as Spring Boot can do that for you.

Add database configuration properties

In the application.properties Spring Boot configuration file, you have the add your database configuration properties:

spring.datasource.driverClassName = org.postgresql.Driver
spring.datasource.url = jdbc:postgresql://localhost:5432/teste
spring.datasource.username = klebermo
spring.datasource.password = 123

Add Hibernate specific properties

And, in the same application.properties configuration file, you can also set custom Hibernate properties:

# Log SQL statements
spring.jpa.show-sql = false

# Hibernate ddl auto for generating the database schema
spring.jpa.hibernate.ddl-auto = create

# Hibernate database Dialect
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

That's it!

Yogeshivu N
  • 5
  • 1
  • 7
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • 1
    Adding spring.jpa.properties.hibernate.dialect to the application.properties helped me. Thank you) – Maks May 07 '20 at 16:12
  • This does not work if you use multiple data sources for databases by different vendors. for example if you have one data source for DB2 and another for Oracle, this will not work. – pixel May 18 '22 at 20:57
14

I ran into the same problem and my issue was that the DB I was trying to connect to didn't exist.

I created the DB, verified the URL/connection string and reran and everything worked as expected.

Eric B.
  • 23,425
  • 50
  • 169
  • 316
13

I had same issue. adding this to the application.properties solved the issue:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
Arthur Kazemi
  • 960
  • 1
  • 10
  • 11
  • Adding spring.jpa.properties.hibernate.dialect to the application.properties helped me. Thank you) – Maks May 07 '20 at 16:12
  • 1
    This does not work if you use multiple data sources for databases by different vendors. for example if you have one data source for DB2 and another for Oracle, this will not work. – pixel May 18 '22 at 20:57
  • @pixel In the world of microservices I assume we have different services dealing with different data and therefore different data sources and configs – Arthur Kazemi Nov 20 '22 at 11:43
  • Sure @ArthurKazemi. Still nothing to do with my comment. Different data source for save database vendor is not same as different data sources for different database vendors – pixel Nov 21 '22 at 13:20
8

The following are some of the reasons for the hibernate.dialect not set issue. Most of these exceptions are shown in the startup log which is finally followed by the mentioned issue.

Example: In Spring boot app with Postgres DB

1. Check if the database is actually installed and its server is started.

  • org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  • java.net.ConnectException: Connection refused: connect
  • org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

2. Check if the database name is correctly mentioned.

  • org.postgresql.util.PSQLException: FATAL: database "foo" does not exist

    In application.properties file,

    spring.datasource.url = jdbc:postgresql://localhost:5432/foo
    

    but foo didn't exist. So I created the database from pgAdmin for postgres

    CREATE DATABASE foo;
    

3. Check if the host name and server port is accessible.

  • org.postgresql.util.PSQLException: Connection to localhost:5431 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  • java.net.ConnectException: Connection refused: connect

4. Check if the database credentials are correct.

  • as @Pankaj mentioned
  • org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"

    spring.datasource.username= {DB USERNAME HERE}

    spring.datasource.password= {DB PASSWORD HERE}

abitcode
  • 1,420
  • 17
  • 24
  • Very good answer, I would complement it with: If you are using ssh tunnel or vpn to access your db, check that you are on line – Adán Escobar Aug 10 '22 at 14:09
6

In spring boot for jpa java config you need to extend JpaBaseConfiguration and implement it's abstract methods.

@Configuration
public class JpaConfig extends JpaBaseConfiguration {

    @Override
    protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
        final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        return vendorAdapter;
    }

    @Override
    protected Map<String, Object> getVendorProperties() {
        Map<String, Object> properties = new HashMap<>();
        properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
    }

}
Yaroslav
  • 111
  • 4
  • 3
  • some cases application.properties cannot see the properties changes.And i added properties.put like above and worked fine.Thx for reply. – fatih yavuz Feb 19 '20 at 08:12
4

Make sure your application.properties has all correct info: (I changed my db port from 8889 to 3306 it worked)

 db.url: jdbc:mysql://localhost:3306/test
Michał
  • 616
  • 1
  • 7
  • 22
Vikram S
  • 551
  • 5
  • 5
4

this is happening because your code is not bale to connect the database. Make sure you have mysql driver and username, password correct.

4

It turns out there is no one mentioning set spring.jpa.database=mysql in application.properties file, if you use Spring JPA. This is the simplest answer to me and I want to share in this question.

Chayne P. S.
  • 1,558
  • 12
  • 17
2

In my case the user could not connect to the database. If will have same issue if the log contains a warning just before the exception:

WARN HHH000342: Could not obtain connection to query metadata : Login failed for user 'my_user'.
zbig
  • 3,830
  • 2
  • 29
  • 37
2

Make sure you have your database in your pom like OP did. That was my problem.

obesechicken13
  • 795
  • 1
  • 12
  • 24
2

My problem was that embedded database was already connected. close connection

doesnt_matter
  • 121
  • 5
  • 13
  • 1
    I can confirm that there is some kind of Hibernate problem that reports this error when it fails to connect. I could reproduce the problem switching on and off the network. – borjab Apr 20 '17 at 07:45
2

I got this issue when Eclipse was unable to find the JDBC driver. Had to do a gradle refresh from the eclipse to get this work.

Kannan Ramamoorthy
  • 3,980
  • 9
  • 45
  • 63
2

I had the same issue and after debugging it turns out that Spring application.properties had wrong IP address for DB server

spring.datasource.url=jdbc:oracle:thin:@WRONG:1521/DEV
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
1

If you are using this line:

sessionFactory.getHibernateProperties().put("hibernate.dialect", env.getProperty("hibernate.dialect"));

make sure that env.getProperty("hibernate.dialect") is not null.

zygimantus
  • 3,649
  • 4
  • 39
  • 54
1

Same but in a JBoss WildFly AS.

Solved with properties in my META-INF/persistence.xml

<properties>
            <property name="hibernate.transaction.jta.platform"
                value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
            <property name="spring.jpa.database-platform" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="spring.jpa.show-sql" value="false" />
</properties>
1

For those working with AWS MySQL RDS, it may occur when you are unable to connect to the database. Go to AWS Security Groups setting for MySQL RDS and edit the inbound IP rule by refreshing MyIP.

I faced this issue and doing above got the problem fixed for me.

Ajitesh
  • 956
  • 10
  • 14
  • I allowed all traffic to the security group of the RDS Aurora MySQL, this did the trick for me. If u want to be more specific or for prod env, add only the allowed ips – alext Dec 12 '19 at 11:36
1

I also had this problem. In my case it was because of no grants were assigned to MySQL user. Assigning grants to MySQL user which my app uses resolved the issue:

grant select, insert, delete, update on my_db.* to 'my_user'@'%';
Yamashiro Rion
  • 1,778
  • 1
  • 20
  • 31
1

Adding spring.jpa.database-platform=org.hibernate.dialect.MariaDB53Dialect to my properties file worked for me.

PS: i'm using MariaDB

Joel Mata
  • 456
  • 4
  • 8
1

I reproduced this error message in the following three cases:

  • There does not exist database user with username written in application.properties file or persistence.properties file or, as in your case, in HibernateConfig file
  • The deployed database has that user but user is identified by different password than that in one of above files
  • The database has that user and the passwords match but that user does not have all privileges needed to accomplish all database tasks that your spring-boot app does

The obvious solution is to create new database user with the same username and password as in the spring-boot app or change username and password in your spring-boot app files to match an existing database user and grant sufficient privileges to that database user. In case of MySQL database this can be done as shown below:

mysql -u root -p 
>CREATE USER 'theuser'@'localhost' IDENTIFIED BY 'thepassword';
>GRANT ALL ON *.* to theuser@localhost IDENTIFIED BY 'thepassword';
>FLUSH PRIVILEGES;

Obviously there are similar commands in Postgresql but I haven't tested if in case of Postgresql this error message can be reproduced in these three cases.

0

I had the same issue and it was caused by being unable to connect to the database instance. Look for hibernate error HHH000342 in the log above that error, it should give you an idea to where the db connection is failing (incorrect username/pass, url, etc.)

Farouk
  • 91
  • 1
  • 4
0

This happened to me because I hadn't added the conf.configure(); before beginning the session:

Configuration conf = new Configuration();
conf.configure();
Michael
  • 41,989
  • 11
  • 82
  • 128
diana
  • 1
0

Make sure that you have enter valid detail in application.properties and whether your database server is available. As a example when you are connecting with MySQL check whether XAMPP is running properly.

Lahiru Gamage
  • 849
  • 5
  • 14
  • 27
0

I faced the same issue: The db I was trying to connect did not exist. I used jpa.database=default (which I guess means it will try to connect to the database and then auto select the dialect). Once I started the database, it worked fine without any change.

ascripter
  • 5,665
  • 12
  • 45
  • 68
0

I had the same error after using the hibernate code generation

https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/

then the hibernate.cfg.xml was created in /src/main/java but without the connection parameters after removing it - my problem was solved

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
RMagen
  • 612
  • 2
  • 9
  • 23
0

I faced this issue due to Mysql 8.0.11 version reverting back to 5.7 solved for me

0

If the preceding error in log was this: "ERROR - HikariPool-1 - jdbcUrl is required with driverClassName" then the solution is to rewrite "url" to "jdbc-url" according to this: Database application.yml for Spring boot from applications.properties

JanBrus
  • 1,198
  • 9
  • 13
0

I had the same Error,

 Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

in my case the WAR had application.properties inside that pointed to development server
where external application.properties was pointing to the right DB server.

make sure you don't have any other application.properties in the classpath / jars...

JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
0

In my case, the root cause of this exception comes from using an old version mysql-connector and I had this error :

unable to load authentication plugin 'caching_sha2_password'. mysql

Adding this line to the mysql server configuration file (my.cnf or my.ini) fix this issue :

default_authentication_plugin=mysql_native_password

Dimitri
  • 8,122
  • 19
  • 71
  • 128
0

As a more descriptive answer


To fix the issue which is related to connecting to the database:

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    ... 38 common frames omitted

everything you need to do is:

  1. To choose specific Data Source configuration option related to the required database (which you are using inside your application.properties file), e.g. you have spring.datasource.platform=postgres:

enter image description here

  1. To avoid "FATAL: database "testDb" does not exist" while connecting:

enter image description here

using PgAdmin needs to create manually the database (if you are using the development platform for PostgreSQL):

enter image description here

based on your property inside application.properties file:

spring.datasource.url=jdbc:postgresql://localhost:5432/testDb
  1. Configure remaining settings:
  • spring.datasource.url=jdbc:postgresql://localhost:5432/testDb
  • spring.datasource.username=postgres
  • spring.datasource.password=your_password

based on your application.properties file:

enter image description here

  1. Click "Test Connection" and "Apply".
invzbl3
  • 5,872
  • 9
  • 36
  • 76
0

For me, The problem solved by doing as following :

Right click on Entities on Persistence window and select related data source

Tohid Makari
  • 1,700
  • 3
  • 15
  • 29
0

Checking the code (HibernateJpaVendorAdapter && JdbcEnvironmentInitiator), the fallback looks like this:

  • if spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults is true then the dialect is obtained from the db.
    • Else, if spring.jpa.database-platform is set, get the dialect from there
      • Else, if spring.jpa.database is set, get a default hardocded dialect mapped in HibernateJpaVendorAdapter
Whimusical
  • 6,401
  • 11
  • 62
  • 105
0

I solved this problem by adding in hibernate.cfg.xml:

<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

Granted, I upgraded Spring and Hibernate on a very old application and did not refactor it to new standards, thus for most people, this solution is irrelevant as it applies only to application configured the old fashion way.

Hans Deragon
  • 504
  • 1
  • 7
  • 17