• pom.xml
<properties>
  <ojdbc17.version>23.7.0.25.01</ojdbc17.version>
  <!--
    hibernate.version set 6.6.26.Final
    postgresql.version set to 42.7.7
    via spring-boot-dependencies-3.5.x.pom
  -->
</properties>

<build>
...
</build>

<profiles>
  <profile>
    <id>generate-jpa-entities</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.hibernate.tool</groupId>
          <artifactId>hibernate-tools-maven</artifactId>
          <version>${hibernate.version}</version>
          <dependencies>
            <dependency>
              <groupId>org.hibernate.tool</groupId>
              <artifactId>hibernate-tools-orm</artifactId>
              <version>${hibernate.version}</version>
            </dependency>
            <dependency>
              <groupId>org.postgresql</groupId>
              <artifactId>postgresql</artifactId>
              <version>${postgresql.version}</version>
            </dependency>
          </dependencies>
          <executions>
            <execution>
              <id>generate-jpa-entities</id>
              <phase>generate-sources</phase>
              <goals>
                <goal>hbm2java</goal>
              </goals>
              <configuration>
                <ejb3>true</ejb3>
              </configuration>
            </execution>
          </executions>
          <configuration>
            <detectManyToMany>true</detectManyToMany>
            <detectOneToOne>true</detectOneToOne>
            <detectOptimisticLock>false</detectOptimisticLock>
            <createCollectionForForeignKey>true</createCollectionForForeignKey>
            <createManyToOneForForeignKey>true</createManyToOneForForeignKey>
            <packageName>com.asimiotech.demo.domain</packageName>
            <propertyFile>${project.basedir}/src/main/resources/hbm2java/hibernate-postgres.properties</propertyFile>
            <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>


  • src/main/resources/hbm2java/hibernate-postgres.properties
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql://asimio-nas:5432/db_dvdrental
hibernate.connection.username=user_dvdrental
hibernate.connection.password=changeit
hibernate.default_schema=public


Usage

mvn generate-sources -Pgenerate-jpa-entities
...
[INFO] Finished GenerateJavaMojo!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...


ls target/generated-sources/com/asimiotech/demo/domain/
Actor.java			CustomerList.java		FilmListId.java			PaymentP200702.java		PaymentP200706.java		StaffList.java
ActorInfo.java			CustomerListId.java		Inventory.java			PaymentP200702Id.java		PaymentP200706Id.java		StaffListId.java
ActorInfoId.java		Film.java			Language.java			PaymentP200703.java		Rental.java			Store.java
Address.java			FilmActor.java			NicerButSlowerFilmList.java	PaymentP200703Id.java		SalesByFilmCategory.java
Category.java			FilmActorId.java		NicerButSlowerFilmListId.java	PaymentP200704.java		SalesByFilmCategoryId.java
City.java			FilmCategory.java		Payment.java			PaymentP200704Id.java		SalesByStore.java
Country.java			FilmCategoryId.java		PaymentP200701.java		PaymentP200705.java		SalesByStoreId.java
Customer.java			FilmList.java			PaymentP200701Id.java		PaymentP200705Id.java		Staff.java