skip to Main Content

I’m working on a Spring Boot project that connects to a PostgreSQL database, but I’m encountering issues with the database connection setup. The logs show the following:

The database driver is reported as "undefined/unknown."

There are warnings related to Hibernate, specifically about the dialect and JTA platform. Hikari connection pool is not showing the expected configuration, such as the pool size, isolation level, and autocommit mode.

I’ve already added the PostgreSQL dependency, but the connection still seems to have issues during the startup. Can anyone help troubleshoot the setup or suggest additional configuration steps to resolve this problem?

application.properties file

spring.application.name=demo
spring.datasource.url=jdbc:postgresql://localhost:5432/student
spring.datasource.username=postgres
spring.datasource.password=""
spring.jpa.hibernate.ddl-auto=update

pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

terminal result

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.1)

2024-12-21T21:27:34.587+08:00  INFO 31236 --- [demo] [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 23.0.1 with PID 31236 (D:Self-LearnJavademotargetclasses started by shien in D:Self-LearnJavademo)
2024-12-21T21:27:34.589+08:00  INFO 31236 --- [demo] [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2024-12-21T21:27:35.339+08:00  INFO 31236 --- [demo] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-12-21T21:27:35.364+08:00  INFO 31236 --- [demo] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 12 ms. Found 0 JPA repository interfaces.
2024-12-21T21:27:35.903+08:00  INFO 31236 --- [demo] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-12-21T21:27:35.921+08:00  INFO 31236 --- [demo] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-12-21T21:27:35.921+08:00  INFO 31236 --- [demo] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.34]
2024-12-21T21:27:35.985+08:00  INFO 31236 --- [demo] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-12-21T21:27:35.987+08:00  INFO 31236 --- [demo] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1315 ms
2024-12-21T21:27:36.209+08:00  INFO 31236 --- [demo] [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-12-21T21:27:36.282+08:00  INFO 31236 --- [demo] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.6.4.Final
2024-12-21T21:27:36.322+08:00  INFO 31236 --- [demo] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2024-12-21T21:27:36.600+08:00  INFO 31236 --- [demo] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-12-21T21:27:36.627+08:00  INFO 31236 --- [demo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-12-21T21:27:36.836+08:00  INFO 31236 --- [demo] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@3cf55e0c
2024-12-21T21:27:36.838+08:00  INFO 31236 --- [demo] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-12-21T21:27:36.911+08:00  INFO 31236 --- [demo] [           main] org.hibernate.orm.connections.pooling    : HHH10001005: Database info:
    Database JDBC URL [Connecting through datasource 'HikariDataSource (HikariPool-1)']
    Database driver: undefined/unknown
    Database version: 17.2
    Autocommit mode: undefined/unknown
    Isolation level: undefined/unknown
    Minimum pool size: undefined/unknown
    Maximum pool size: undefined/unknown
2024-12-21T21:27:37.276+08:00  INFO 31236 --- [demo] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-12-21T21:27:37.280+08:00  INFO 31236 --- [demo] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-12-21T21:27:37.342+08:00  WARN 31236 --- [demo] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-12-21T21:27:37.795+08:00  INFO 31236 --- [demo] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2024-12-21T21:27:37.804+08:00  INFO 31236 --- [demo] [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.664 seconds (process running for 4.177)

2

Answers


  1. Did you create a database named ‘student’ on PostgreSQL? If not, can you try this?

    spring.datasource.driver-class-name=org.postgresql.Driver
    spring.application.name=demo
    spring.datasource.url=jdbc:postgresql://localhost:5432/student
    spring.datasource.username=postgres
    spring.datasource.password=""
    spring.jpa.hibernate.ddl-auto=update
    
    Login or Signup to reply.
  2. You need to set the connection configuration in your application properties file. I think it used to automatically infer it from spring.datasource but now you have to manually set it in spring.jpa.properties.hibernate.connection as well.

    spring:
      jpa:
        hibernate:
          ddl-auto: update
        properties:
          hibernate:
            dialect: org.hibernate.dialect.PostgreSQLDialect
            connection:
              driver_class: org.postgresql.Driver
              url: jdbc:postgresql://localhost:5432/your-database-name
              username: postgres
              password: ''
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search