Hibernate Pojo Generator is a program that generates all the Java code necessary to access a database via Hibernate Annotations (+ Spring) including JUnit tests (1 per table) that are able to run immediately without further customizations.
What does it do?
Given an accessible database schema, the Hibernate POJO Generator produces all the Java code necessary to access each field in each table via the Hibernate persistence framework. Additionally, the generator also creates all the necessary helper classes and test units for each component.
How does it work?
The generator uses JDBC to look at your database metadata to obtain the relationships between the tables, field types and so on. Once this is done, it constructs an object model representing the tables in the java world and thereafter uses Velocity as a templating engine to actually write out your source code.
The whole process, usually lasting just several seconds, is completely automated and requires no further interaction on your part.
What about the generated code?
A lot of work has gone into ensuring the resultant code is free from any errors, warnings or broken conventions. At the end of the run, your target folder will contain:
* A class for each table in your database
* A Data Access Object (+ interface) to access that table
* Enumeration objects pertaining to that class
* Data factories
* JUnit v4 test case per table
* All the relevant hibernate and spring configuration files
* A data services layer containing static methods to access your data (load(..), save(..), etc)
* Other minor stuff like Maven POM files and Ant build files.
Of course, you always have access to both the source code as well as the velocity template files.
I have business logic code...
Keep that in your own services layer. Remember that the generator will build your data layer for you, it is up to your application to provide higher level abstractions for the rest of your codebase. The code generated is meant to be completely overwritten on each database change; indeed it is recommended that you script your changes in such a way so as to regenerate your data layer automatically on each change.
Here are some key features of "Hibernate Pojo Generator":
· Java objects representing each table using annotations for use with Hibernate.
· A JUnit test case per table that uses the objects generated to create, populate, save, retrieve and compare results
· DAO per class
· The appropriate enumeration files
· Spring and hibernate configuration
· DAO layers
· A data factory class per schema to return a pre-populated object with random data (for boundary checking, database population, etc)
· Join tables including those with additional fields in link tables
· Polymorphism/inheritance support
· Composite Keys
· One-To-One, many-to-one, many-to-many, etc
· Multiple schema support (4 modes)
· Natural Keys
· Enumerations (including those entries which cannot be mapped cleanly onto the java world)
· Java 2 Standard Edition Runtime Environment
What's New in This Release: [ read full changelog ]
· re-implementation of equals/hashcode