Harry Gardner

Welcome to Data Access Layer for Java (DAL4j), a command line tool and framework used to reverse engineer a MySQL or SQLServer database tables and views into a set of JPA Entity Beans.

DAL4j can be useful for scenarios where there is an existing database schema but a technology other that JPA is used by applications to interact with the database. DAL4j can provide an relatively pain free way to migrate your code base from other technologies such as JDBC or Hibernate to JPA.

The follow describes how DAL4j is used:

  1. Configure the database to reverse engineer, including:
    • DB connection information
    • Tables and Views to generate code for
    • Package name of generated Entity Beans
    • Directory to generate Entity Beans to
    • The type of code generation to use, simple or framework.
  2. Run a command line tool to automatically connect to the target database and generate JPA Entity Beans for the tables and views found in the configuration file.
  3. Integrate the generated JPA Entity Beans into your application. The generated Entity Beans can be used by a stand alone application, EJB, Spring, etc.
  4. Optionally, add code integrated into your Entity classes into the DAL4j configuration file to allow round-trip code generation. This allows pojo customization's to be applied each time code is generated as the schema evolves. See [round-trip-sample] for an description of how to inject your customization's across code generation runs.

See [ejb-framework-sample] which shows how to use DAL4j ejb framework. Using the EJB framework is not required, it is provided to simplify creation of Session Beans in a J2EE environment.

See [database-re-factoring] to see how DAL4j can be used in conjunction with tools like liquibase to keep entities in sync as the schema changes.

There are currently two different types of code generators that DAL4j can use to generate Entity Beans:

com.dal4j.jpa.tools.cod]egen.SimplePojoGenerator - This class generates traditional Entity beans not for use with the DAL4j Framework. One possible use of this generator is one-time schema reverse engineering. In this case one-to-many or many-to-one associations can be manually added to the generated entities and the entities would be manually maintained going forward. See [samples-simple] for an example of a project that generates and shows usage of DAL4j Simple Entity Beans.

com.dal4j.jpa.tools.codegen.FrameworkPojoGenerator - This class generates Entity beans that inherit from the DAL4j framework classes. These beans can be used in conjunction with DAL4j framework classes such as EntityDAO<C> and DAOFactory. See [samples-framework] for an example of a project that generates and shows usage of DAL4j framework Entity Beans in a stand alone application. Two additional examples also exist that show usage of framework generated Entity Beans in EJB session beans [samples-ejb] and the last example [ejb-framework-sample] which shows usage of the DAL4j EJB framework.

See the [Code-Generation] page for a description of the code generation command line tools.

See the [type-mapping] page to customize how database types are mapped during code generation.

The wiki uses Markdown syntax.


Wiki: Code-Generation
Wiki: database-re-factoring
Wiki: ejb-framework-sample
Wiki: round-trip-sample
Wiki: samples-ejb
Wiki: samples-framework
Wiki: samples-simple
Wiki: type-mapping