Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set using spring-boot

I am trying to configure hibernate in my spring-boot project.

I have application.properties file

spring.datasource.url=jdbc:mysql:url?useSSL=false
spring.datasource.username=name
spring.datasource.password=password

hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql:url
hibernate.connection.username = name
hibernate.connection.password = password
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect=org.hibernate.dialect.MySQLDialect

And method for registering user in UserDAO class:

public void registerUser(User u){
    Session session = factory.openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();
        session.save(u);
        tx.commit();
    } catch (HibernateException e) {
        if (tx!=null) tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
    System.out.println("yay all done");
}

However i am recieving error:

> Caused by: org.hibernate.service.spi.ServiceException: Unable to
> create requested service
> [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:179)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:119)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> com.groups.data.UserDAO.<init>(UserDAO.java:18) ~[classes/:na]    ... 52
> common frames omitted 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.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
> ~[hibernate-core-5.3.2.Final.jar:5.3.2.Final]     ... 66 common frames
> omitted

I have configured dialect as it requires, i have even tried creating good old hibernate.cfg.xml file but the error remained the same ( it even seemed it ignored the file).

Why is ist happening? Literally yesterday it worked without problem. Today i tried creating the cfg file and it stopped working ( deleted it already ).

The more i try to configure hibernate the more it seems it was made to anger anyone who is using it and impossible to make it work.

WHat could be the problem here?

Thanks for help!

like image 786
Darlyn Avatar asked Aug 14 '18 18:08

Darlyn


1 Answers

Have you added this line to your application.properties file ?

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

DB2
org.hibernate.dialect.DB2Dialect

DB2 AS/400
org.hibernate.dialect.DB2400Dialect

DB2 OS390
org.hibernate.dialect.DB2390Dialect

PostgreSQL
org.hibernate.dialect.PostgreSQLDialect

MySQL
org.hibernate.dialect.MySQLDialect

MySQL with InnoDB
org.hibernate.dialect.MySQLInnoDBDialect

MySQL with MyISAM
org.hibernate.dialect.MySQLMyISAMDialect

Oracle (any version)
org.hibernate.dialect.OracleDialect

Oracle 9i/10g
org.hibernate.dialect.Oracle9Dialect

Sybase
org.hibernate.dialect.SybaseDialect

Sybase Anywhere
org.hibernate.dialect.SybaseAnywhereDialect

Microsoft SQL Server
org.hibernate.dialect.SQLServerDialect

SAP DB
org.hibernate.dialect.SAPDBDialect

Informix
org.hibernate.dialect.InformixDialect

HypersonicSQL
org.hibernate.dialect.HSQLDialect

Ingres
org.hibernate.dialect.IngresDialect

Progress
org.hibernate.dialect.ProgressDialect

Mckoi SQL
org.hibernate.dialect.MckoiDialect

Interbase
org.hibernate.dialect.InterbaseDialect

Pointbase
org.hibernate.dialect.PointbaseDialect

FrontBase
org.hibernate.dialect.FrontbaseDialect

Firebird
org.hibernate.dialect.FirebirdDialect

like image 143
Eddy Avatar answered Nov 15 '22 15:11

Eddy