Home > Enterprise >  spring jpa connect failed to postgres server
spring jpa connect failed to postgres server

Time:02-21

I create spring project to do the CRUD to the postgres database server but get some error.

HHH000342: Could not obtain connection to query metadata

org.postgresql.util.PSQLException: The connection attempt failed. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.jdbc.PgConnection.(PgConnection.java:225) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.Driver.makeConnection(Driver.java:466) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.Driver.connect(Driver.java:265) ~[postgresql-42.3.1.jar:42.3.1] at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]

Here is my application.properties

spring.datasource.url=jdbc:postgresql://3.1.84.18:5432/postgres

spring.datasource.username=postgres

spring.datasource.password=postgres

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

spring.jpa.hibernate.ddl-auto=none spring.jpa.show-sql=true

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

my pom.xml

enter image description here

CodePudding user response:

Your pom.xml is correct

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <scope>runtime</scope>
</dependency>

After you must create a postgre user with a password, and then create a postgre database

And on your application.properties, you can use the user created with his password

spring.datasource.database-platform=org.hibernate.dialect.PostgreSQLDialect 
spring.datasource.url=jdbc:postgresql://localhost:5432/database_name
spring.datasource.username=user_name
spring.datasource.password=user_password
spring.jpa.hibernate.ddl-auto=update

CodePudding user response:

my issues is, after trying to resolve "not connected to the database", I changed the pg_hba.conf with host all all 0.0.0.0/0 ident we retry with host all all 0.0.0.0/0 md5, and issue got resolved.

thank you

  • Related