13 April 2022

What's new in JPA Buddy 2022.2

A lot has happened over the last three releases of JPA Buddy. In this article, we will take a look at the major improvements and new features. Also, since this release of JPA Buddy, some of the features became available only under the commercial subscription. Check out this article to find out our motivation to do this, instructions on how to buy the subscription and conditions for getting paid features for free.

Entities from DB Generation

One of the most beloved features of our users has become Reverse Engineering, and we are doing our best to keep it on top of the most loved features list. We began our improvements for this feature from the existing wizard. All attributes detected by the wizard, are now divided into three categories:

  1. Migrated Columns - the ones which already exist in the entity
  2. New Columns – mapped neither in the current entity nor in parent @MappedSuperclass yet
  3. References - optional associations that are not represented as columns in a table

The implementation of the third category has also become part of the next major improvement: a scrupulous determination of the cardinality of the association. For now, in most cases, JPA Buddy can detect cardinality with absolute confidence.

For example, to establish a many-to-many relationship between two tables in the database, we need to use a junction table that contains only two columns - foreign keys to the corresponding tables. When JPA Buddy finds such a table, it can determine that the relation cardinality between two tables is many-to-many. Then the plugin will create references in the generated entities based on the foreign keys detected the junction table.

It also works with @OneToMany, @ManyToOne and @OneToOne associations. You can find a full explanation of how JPA Buddy "thinks" (with examples and short videos) in our documentation.

So far, this feature works great! But there is one more thing: it would be really cool if you could create entities for all tables at once, and not just for one, wouldn't it? And we've implemented it! Now you can call JPA Buddy wizard once and create entities for many tables and views presented in the database. Look how quickly and easily we can create a JPA model with a dozen entities from an existing database:

Database Versioning

The migration script generator has become even handier. Now, you can preview all the changes that are generated for both Flyway and Liquibase:

JPA Buddy provides some optimization hints for migration scripts. For example, you can merge some statements to simplify the resulting migration/changelog right in the preview window. Imagine that you rename a column. DB versioning engine will generate two statements for this case:

  1. Dropping the column
  2. Adding a new one with a new name

In JPA Buddy, you can choose any of the related statements and merge them:

Also, there are some great news for Liquibase fans, who prefer YAML, JSON or SQL formats to XML. JPA Buddy now supports all these formats as well! Pick the one you like the most!

Those developers who do not use DB migration engines for some reason, create schema.sql and data.sql files to initialize the database in the Spring Boot application. JPA Buddy makes it easier to add proper DDL into these files. You can generate a schema initialization script via a special action and create insert/update statements using convenient wizards.

For example, we can use schema initialization scripts while creating app integration tests with Testcontainers. In the following video guide, we generate schema creation SQL for the whole test suite and create test data for a particular test only. But DB initialization is not the only topic covered by the guide, though. Watch the video to learn the application integration testing process in detail:

DTO Generator

DTO is an essential pattern for web apps. For example, if you need to expose only a few of the entity attributes via REST API, you usually map entities to DTOs with those attributes and serialize only them. But then the question arises: "how to transform an entity to DTO and back easily with the minimum boilerplate code?". According to our twitter poll, the most popular solution for this problem is MapStruct.

That's why we've added MapStruct support and simplified DTO generation. Now you can use GUI wizards to create DTOs and create mappers along the way:

However, you can notice that writing mappers manually is also quite popular. In such cases, JPA Buddy will help you too! If you have unresolved references in MapStruct interfaces, Spring Data repositories or ModelMappers, you can invoke the "Create DTO" or "Create JPA Projection" wizards right from the source code:

Entity Designer

Even though we have been updating the entity designer since the first release, there is always room for improvement. One of these nuances was the correct declaration of associations that do not harm the application's performance. Now, while creating associations with JPA Buddy, you are unlikely to miss the moment of defining a low-performance collection for to-many associations. JPA Buddy will warn you and advise the best performance mapping declaration:

The next improvement is the support of the Hibernate Event System. It is useful when you work with data and need to log or broadcast changes, perform additional checks before irreversible operations, hook business logic when data state gets changed, etc. For all these occasions, Hibernate provides Event Listeners and JPA Buddy is now able to scaffold them in a few clicks:

Spring Data JPA

IntelliJ IDEA inspections is a cool thing that helps to catch errors in advance. Inspections that help with catching errors that might pass the compilation stage and fail only in runtime are especially useful. JPA Buddy has two more inspections in its collection now:

  1. For the missing Pageable parameter
  2. For the missing @Modifying annotation

The EntityGraph feature has been introduced in JPA 2.1, it has been one of the most awaited features for quite a long time. Entity graphs give us another layer of control over data that needs to be fetched. Now JPA Buddy supports them, so you can build graphs using a handy GUI wizard:

Minimalistic Mode

The last but not least feature is the minimalistic mode. It is designed to minimize distraction for developers. If you are the one who prefers to have everything at your fingertips – you will like it! All JPA Buddy panels will be hidden, and their content will be available in standard IntelliJ IDEA windows, such as Project Panel, Generate Menu and so on...

Using Spring Data JPA, Hibernate or EclipseLink and code in IntelliJ IDEA? Make sure you are ultimately productive with the JPA Buddy plugin!

It will always give you a valuable hint and even generate the desired piece of code for you: JPA entities and Spring Data repositories, Liquibase changelogs and Flyway migrations, DTOs and MapStruct mappers and even more!


In this article, we have reviewed only some of the features and improvements that were added to the latest releases. Find the full list in our issue tracker (300+ resolved issues). Share your feedback and ideas in our Discord channel and follow us on Twitter to get the latest news about JPA Buddy along with useful JPA tips!