0

Error creating bean with name 'entityManagerFactory' defined in class path resource . I have problem how to config application.properties. It is work perfct with H2, but with Firebird and SpringBoot not. I am new in Spring. @SpringBootApplication work with this beans in xml?

My Connection in application.properties is

spring.datasource.url:jdbc:firebirdsql://localhost:3050/C:/testdata.fdb
spring.datasource.driverClassName:org.firebirdsql.jdbc.FBDriver
spring.datasource.username:SYSDBA
spring.datasource.password:masterkey
spring.jpa.hibernate.ddl-auto:create
spring.jpa.show-sql: true
spring.jpa.properties.hibernate.format_sql=true
firebird.connection.type=TYPE4

my xml code is:

<?xml version="1.0" encoding="UTF-8"?>


    <bean id="dataSource" class="org.firebirdsql.pool.FBWrappingDataSource">
        <property name="database">
            <value>${firebird.database}</value>
        </property>
        <property name="userName">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
        <property name="maxPoolSize">
            <value>${jdbc.maxPoolSize}</value>
        </property>
        <property name="minPoolSize">
            <value>${jdbc.minPoolSize}</value>
        </property>
        <property name="maxStatements">
            <value>${jdbc.maxStatements}</value>
        </property>
        <property name="type">
            <value>${firebird.connection.type}</value>
        </property>
    </bean>

My error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
    at com.BookStoreDemo.bookStoreDemo.BookStoreDemoApplication.main(BookStoreDemoApplication.java:13) [classes/:na]
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:271) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    ... 16 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.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) ~[hibernate-core-5.2.13.Final.jar:5.2.13.Final]
    ... 33 common frames omitted
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Please do not use `org.firebirdsql.pool.FBWrappingDataSource`, it is buggy and shouldn't be used. It is deprecated in Jaybird 2.2 and has been removed in Jaybird 3.0. Prefer using something like HikariCP or DBCP instead. – Mark Rotteveel Mar 20 '18 at 21:41
  • You shouldn't even need it, given you're configuring `spring.datasource.*` properties. Your problem might be elsewhere, make sure you don't have other errors earlier. See also https://stackoverflow.com/questions/26548505/org-hibernate-hibernateexception-access-to-dialectresolutioninfo-cannot-be-null – Mark Rotteveel Mar 20 '18 at 21:46

1 Answers1

1

This question, org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set, suggests this problem may occur if there is a problem connecting. Given you haven't shown the presence of the properties firebird.database, jdbc.username etc, that may likely be the immediate cause. As I suggested in the comments yesterday, you may also want to check if there are any errors earlier in the logs.

However, the better way to fix this would be to remove the XML configuration for the data source. There are two reasons:

  1. The FBWrappingDataSource you specified is buggy (it is deprecated in Jaybird 2.2 and has been removed in Jaybird 3), the advice is to use a dedicated connection pool library like HikariCP
  2. Spring will automatically configure a suitable datasource (default is HikariCP in Spring Boot 2) provided the spring.datasource.url and spring.datasource.driverClassName has been populated. Consult the Spring Boot documentation for further config (like managing the number of connections in the pool, etc).

As an example, I created a (Gradle) project from scratch on https://start.spring.io/ with just JPA and Web enabled, and made the following modifications:

In build.gradle (in dependencies), I added a dependency to Jaybird:

compile('org.firebirdsql.jdbc:jaybird-jdk18')

This defaults to Jaybird 3.0.3 (latest at this time) when using Spring Boot 2.0.0.RELEASE

In application.properties, I set:

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:firebirdsql://localhost/employee
spring.datasource.hikari.data-source-properties.charSet=utf-8
spring.datasource.username=sysdba
spring.datasource.password=masterkey

Note I'm using the example Employee database shipped with Firebird (with the alias employee defined).

Next I created a skeleton Employee class:

package example;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer empNo;

    private String firstName;
    private String lastName;

    public Integer getEmpNo() {
        return empNo;
    }

    public void setEmpNo(Integer empNo) {
        this.empNo = empNo;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}

Repository EmployeeRepository:

package example;

import org.springframework.data.repository.CrudRepository;

public interface EmployeeRepository extends CrudRepository<Employee, Integer> {
}

And a controller:

package example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path = "/demo")
public class MainController {

    @Autowired
    private EmployeeRepository employeeRepository;

    @GetMapping(path="/all")
    public @ResponseBody
    Iterable<Employee> getAllUsers() {
        return employeeRepository.findAll();
    }
}

Starting the application and opening http://localhost:8080/demo/all is sufficient to query the database. And if you check the logging, you will notice that Hibernate will correctly select the Firebird dialect:

[..] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.FirebirdDialect

In short, the main solution is to use the default Spring Boot configuration and rely more on the automatic configuration of Spring Boot, and less on trying to do things the 'old' way (Spring XML configs, etc).

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Thank you, but now I got messege : `Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource: Property: driverclassname Value: org.firebirdsql.jdbc.FBDriver Origin: "driverClassName" from property source "source" Reason: Unable to set value for property driver-class-name Action: Update your application's configuration` – Mantas Pauliukonis Mar 22 '18 at 16:13
  • 1
    Finaly, delete scope in dependency and working, thank you, very very very – Mantas Pauliukonis Mar 22 '18 at 16:38