2

I have a problem when connect Spring Boot with PostgreSQL. I can't seem to make it work. If there's anything missing I can give it more to you but for now this is enough information

the full error:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project resorts-restful-project: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.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]: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 

heres my configuration:

application.properties:

spring.datasource.url= jdbc:postgresql://localhost:5433/qwerty
spring.datasource.username=postgres spring.datasource.password=postgres@qwerty
spring.jpa.hibernate.ddl-auto=create-drop

my model:

package com.fvthree.domain;

import javax.persistence.*;
import java.io.Serializable;

@Entity
public class Resort implements Serializable {
    @Id
    @GeneratedValue
    @Column(name="resorts_id")
    private Long id;

    @Column(name="name")
    private String name;
    @Column(name="location")
    private String location;

    @Column(name="contact_id")
    private Long contactId;

    public Resort() {
    }

    public Resort(Long id, String name, String location, Long contactId) {
        this.id = id;
        this.name = name;
        this.location = location;
        this.contactId = contactId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Long getContactId() {
        return contactId;
    }

    public void setContactId(Long contactId) {
        this.contactId = contactId;
    }
}
0

3 Answers 3

4

Make sure you have all these properties set:

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=

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

And you have these annotations enabled on the class with main():

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {


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

} 
Sign up to request clarification or add additional context in comments.

Comments

1

I already fixed the problem.

application.properties file needs to be complete:

# Configure postgres

spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/qweqwe
spring.datasource.username=postgres
spring.datasource.password=dontcopythis

i also add @EntityScan and @EnableJpaRepositories to the main :

package com.fvthree;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EntityScan(basePackages = {"com.fvthree.domain" })
@EnableJpaRepositories(basePackages = {"com.fvthree.repository"})
public class ResortsRestfulProjectApplication {

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

Comments

1

(1) In your file application.properties, notice that spring.datasource.username=postgres spring.datasource.password=postgres@qwerty is 2 lines, not 1 line.

(2) Because this error:

Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

You are missing hibernate.dialect=...

For example, if you use PostgreSQL 9.5, it will be hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect

Reference: https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/dialect/package-summary.html

3 Comments

Is there a way to get org.hibernate.dialect.PostgreSQL95Dialect to work with spring-boot-starter-data-jpa:1.5.3.RELEASE ? It doesn't contain version of hibernate which would have that.
You should use latest PostgreSQL version, then use org.hibernate.dialect.PostgreSQL95Dialect not org.hibernate.dialect.PostgreSQLDialect Spring Boot 1.5.3.RELEASE use Hibernate managed dependence version 5.0.12.Final . See: docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/dialect/… (section hibernate-orm) and docs.spring.io/spring-boot/docs/current/reference/htmlsingle/…
You must override managed dependency version. But it make instability for your application.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.