Can you help to check why this is happening. My Postgres in Springboot is not auto create run I run my Java program. SHould be it auto create since I put in my application.properties:

spring.jpa.hibernate.ddl-auto=update

Here is my pom.xml file:

<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.2</version>
        <relativePath/>
    </parent>
    <groupId>com.hr-software-project</groupId>
    <artifactId>hr-management</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>hr-management</name>
    <description>HR Management Service</description>
    <properties>
        <java.version>21</java.version>
    </properties>
    <dependencies>
        <!-- Spring Boot Core Dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- Database -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- JJWT for JWT Authentication -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Swagger/OpenAPI -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.7.0-RC1</version> <!-- Update version to ensure compatibility -->
        </dependency>
        <!-- Testing -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Here my application.properties:

spring.application.name=hr-management

# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/hr_service
spring.datasource.username=postgres
spring.datasource.password=admin
#spring.datasource.username=${DB_USERNAME:postgres}
#spring.datasource.password=${DB_PASSWORD:admin}

# JPA & Hibernate
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.generate-ddl=true

# Swagger / OpenAPI
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true
springdoc.swagger-ui.doc-expansion=LIST # Show controllers expanded but keep endpoints collapsed
springdoc.swagger-ui.tags-sorter=alpha  # Sort controllers alphabetically
springdoc.swagger-ui.default-model-expand-depth=99
springdoc.swagger-ui.default-model-rendering=example

My DO somehow something like this:

package com.hr_software_project.hr_management.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Table(name = "leave_types")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class LeaveTypeDO {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name; // e.g., Annual Leave, Sick Leave
    private Long minServiceMonths; //Months
    private Long maxServiceMonths; //Months
    private Integer maxDays;
    private String expiryDate;
}

This is the app that I run:

package com.hr_software_project.hr_management;

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
@EnableJpaRepositories
@EntityScan(basePackages = "com.hr_software_project.hr_management.entity")
public class HrManagementApplication {

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

}

Here is the output in console that I get when run the program:



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

 :: Spring Boot ::                (v3.4.2)

2025-02-28T15:46:37.636+08:00  INFO 34080 --- [hr-management] [           main] c.h.h.HrManagementApplication            : Starting HrManagementApplication using Java 21.0.6 with PID 34080 (C:\Users\muhazmi6\OneDrive - Keysight Technologies\Desktop\HR Project\HR-Software\Project\Code\Backend\hr-management\target\classes started by muhazmi6 in C:\Users\muhazmi6\OneDrive - Keysight Technologies\Desktop\HR Project\HR-Software\Project\Code\Backend\hr-management)
2025-02-28T15:46:37.641+08:00  INFO 34080 --- [hr-management] [           main] c.h.h.HrManagementApplication            : No active profile set, falling back to 1 default profile: "default"
2025-02-28T15:46:38.828+08:00  INFO 34080 --- [hr-management] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-02-28T15:46:39.021+08:00  INFO 34080 --- [hr-management] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 177 ms. Found 17 JPA repository interfaces.
2025-02-28T15:46:40.544+08:00  INFO 34080 --- [hr-management] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2025-02-28T15:46:40.559+08:00  INFO 34080 --- [hr-management] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2025-02-28T15:46:40.559+08:00  INFO 34080 --- [hr-management] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.34]
2025-02-28T15:46:40.663+08:00  INFO 34080 --- [hr-management] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2025-02-28T15:46:40.665+08:00  INFO 34080 --- [hr-management] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2925 ms
2025-02-28T15:46:41.013+08:00  INFO 34080 --- [hr-management] [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2025-02-28T15:46:41.191+08:00  INFO 34080 --- [hr-management] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.6.5.Final
2025-02-28T15:46:41.275+08:00  INFO 34080 --- [hr-management] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2025-02-28T15:46:41.815+08:00  INFO 34080 --- [hr-management] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2025-02-28T15:46:41.867+08:00  INFO 34080 --- [hr-management] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2025-02-28T15:46:42.225+08:00  INFO 34080 --- [hr-management] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@560d6d2
2025-02-28T15:46:42.228+08:00  INFO 34080 --- [hr-management] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2025-02-28T15:46:42.291+08:00  INFO 34080 --- [hr-management] [           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.3
        Autocommit mode: undefined/unknown
        Isolation level: undefined/unknown
        Minimum pool size: undefined/unknown
        Maximum pool size: undefined/unknown
2025-02-28T15:46:43.755+08:00  INFO 34080 --- [hr-management] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2025-02-28T15:46:43.758+08:00  INFO 34080 --- [hr-management] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2025-02-28T15:46:44.468+08:00  INFO 34080 --- [hr-management] [           main] o.s.d.j.r.query.QueryEnhancerFactory     : Hibernate is in classpath; If applicable, HQL parser will be used.
2025-02-28T15:46:46.446+08:00  WARN 34080 --- [hr-management] [           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
2025-02-28T15:46:46.516+08:00  WARN 34080 --- [hr-management] [           main] .s.s.UserDetailsServiceAutoConfiguration : 

Using generated security password: cb91fe05-d05d-4938-b77b-374fb51fdba9

This generated password is for development use only. Your security configuration must be updated before running your application in production.

2025-02-28T15:46:46.571+08:00  INFO 34080 --- [hr-management] [           main] r$InitializeUserDetailsManagerConfigurer : Global AuthenticationManager configured with UserDetailsService bean with name inMemoryUserDetailsManager
2025-02-28T15:46:47.229+08:00  INFO 34080 --- [hr-management] [           main] o.s.v.b.OptionalValidatorFactoryBean     : Failed to set up a Bean Validation provider: jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2025-02-28T15:46:48.381+08:00  INFO 34080 --- [hr-management] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2025-02-28T15:46:48.398+08:00  INFO 34080 --- [hr-management] [           main] c.h.h.HrManagementApplication            : Started HrManagementApplication in 11.409 seconds (process running for 11.955)

Comment From: bclozel

Thanks for getting in touch, but it feels like this is a question that would be better suited to StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.