When you already have a database and you want to use JPA or Hibernate to access that database you need something that will generate those POJO classes for you with the appropriate annotations. There are some existing solutions but I was not happy with them, so this is Yet Another Pojo Generator.

The generator gets generates as part of the build of DomUI and can be found as utilities/hibernate-generator/target/hibernate-generator.jar, and can be executed as:

java -jar hibernate-generator.jar

The generator so far should work for PostgreSQL and Oracle, with PostgreSQL the one that has been tested. Adding new database types should not be too hard.

The generator does the following:


An example command line invocation would be:

java -jar hibernate-generator.jar -dbtype postgres -db dbusername:dbpasswordl@localhost/database_name -pkgroot org.mydomain.myprogram.database -source /home/jal/myproject/src/main/java -s pdi_meta -s source_mapping -s auth -s definition -s sectormodel

This connects to a PostgreSQL database with the specified username and passwords, loads all tables from the schema's pdi_meta, source_mapping, auth and sectormodel, then generates/updates all classes into the specified directory and package.

The directory and package are separate, so the final directory for the classes is formed by adding the source AND the package name.