Benefits of Code Generation for Data Access Source Code

Although modern Java persistence frameworks such as Spring DAO, Hibernate, and Jdbi make is much easier to write persistence code compared to coding directly at the JDBC level, there is still a need to write classes to represent the data in each table and to represent the results of each query. These classes are typically referred to as Data Transfer Objects (DTOs).

Considering that relational databases often consist of hundreds of tables, even if it only takes a few minutes per table, these still equates to many hours of monotonous low-value development work which is prone to errors and inconsistencies.

Even when this code is written, there is an ongoing maintenance burden as the database schema evolves over time. This article highlights the main benefits of code generation when creating Data Access Objects (DAOs).

Faster Time to Market

It typically takes less than a minute to generate code for even the largest of database schemas, compared to days or weeks of manual coding.

Reduce Maintenance Costs

As databases evolve over time, tables and columns are added, deleted, or modified. It is painstaking work to keep the Java data access code in synchronization and can be error-prone. Using a code generator solves this problem and can be integrated into a project build process through the use of a Gradle or Maven plugin. Generating the code on each build ensures that any breaking changes to the schema are detected at compile-time.

Increased Agility

It is expensive for applications to switch from one persistence framework to another, or to switch from Java to Kotlin, but with a code generator it is possible to re-generate the data access layer in a matter of seconds.

Better Code Quality

It is common for different developers in a development team to use different approachs when implementing code, from naming conventions to different approachs to representing null values and even to exception handling. By using a code generator, it is guaranteed that all data access code is written consistently, which reduces ongoing maintenance costs.

Evaluate Inferno DAO

Inferno DAO can import schemas from any database that has a JDBC driver available and then generate high quality Java source code for popular persistence frameworks such as Hibernate ORM and Spring Data JPA. It can also generate Java DTO classes for use with any persistence framework.

Learn more »