Postgresql error with Spring boot - api

Asked

Viewed 521 times

0

Personal opa I’m making a very simple application, to see how postgresql works. I’m making a Spring Api application.

My class

@Entity

public class Product Implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
private BigDecimal valor;
private int quantidade;

remainder of the code

My build.Radle:

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}

}

Application properties

spring.datasource.url = jdbc:postgresql://localhost:5432/product
spring.datasource.username = postgres
spring.datasource.password = 123
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.show-sql = false
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.format_sql=true

Following errors:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution

inserir a descrição da imagem aqui

  • Man, almost 100% sure that Radle downloaded the corrupt drivers, I can’t tell for sure if the import is correct as I use Maven. But try to clean, delete the package, and download again. And give a check on the properties of postgres, if there is nothing wrong with the connection parameters that you configuring in the properties of the application.

  • @Rodrigonantes in reality the application is getting to the bank, just missing the scheme to be created

1 answer

0


The problem is in your connection URL:

jdbc:postgresql://localhost:5432/product

The exception below your stacktrace (in your image) makes this clear: product database does not exist

Check whether the base product if it is created before the execution of the application, this is no dependencies problem, or entity configuration.

  • Mass I believe that’s right. Actually I found that with Hibernate.ddl-auto: update annotation, it automatically created the database with the table as well as in Mysql. Valeeu

  • It creates only the :) tables Generally the database user used in the application does not have this level of privilege

Browser other questions tagged

You are not signed in. Login or sign up in order to post.