IntelliJ IDEA 2024.2 Help

Coding Assistance

JPA represents the anemic domain model pattern. So, usually, the main domain objects are layered as follows:

  1. Entities contain only data

  2. Spring Data repositories declare CRUD operations for entities

  3. DTOs and mappers that transfer entities to their DTOs

Such segregation looks natural because each layer has its clear responsibility area. However, it brings additional complexity during development due to bad discoverability for different operations available over entities.

JPA Buddy addresses this problem by integrating a lot of coding assistance features for JPA entities, Spring Data repositories, DTOs and MapStruct mappers that make development more straightforward and transparent.

Code Completion

Generate & Inject Spring Data JPA Repositories

To create a new Spring Data JPA repository just start typing the repository name that begins with the entity name (1). Then, the repository wizard will open.

By following the same coding style, you can also inject an existing Spring Data JPA repository (2). Just start typing the existing repository name and JPA Buddy will find it.

spring-data-jpa-repository-generation-injection

According to your injection settings, JPA Buddy will inject the repository into the current class. The example below shows constructor-based injection:

spring-data-jpa-repository-generation-injection

Generate & Call Methods/Queries

With JPA Buddy, you don't need to switch focus between multiple editors. It allows you to call query visual designers right from here:

repository-methods-generation

Also, you can find/create repository methods via entity class name call:

entity-class-name-method-call

Generate & Inject MapStruct Mappers

JPA Buddy is able to generate MapStruct mapper, inject it, and scaffold a proper mapping call. Use "mapTo..." option to generate a new mapper, or apply methods from existing ones (e.g., mapToPetDto for the example below). This feature works for both: single instances and collections of entities or DTOs.

map-to-postfix

Here is the code that JPA Buddy will generate after selecting the mapToPetDto option:

map-to-result

Some developers may choose to declare an object before implementing it. JPA Buddy will help those developers who adhere to this programming style. It suggests creating:

  1. Spring Data JPA Repository – in case the reference ends with the value specified in the Spring Data Repository settings. Default value is Repository.

  2. Projection – in case the reference ends with the value specified in the Projection declaration settings. Default values are: Info, Prj, Projection, VO, Vo, View, Request, Browse.

  3. DTO – in case the reference ends with the value specified in the DTO Declaration Settings. Default value is Dto.

unresolved-references

Then, corresponding wizards will open.

Kotlin Support

All the features that Java developers love are also available to Kotlin fans. Whether you're creating Spring Data repositories on the fly, injecting MapStruct mappers, or scaffolding method calls – JPA Buddy has got you covered. And if you're looking to create a REST endpoint in Kotlin, JPA Buddy makes it incredibly easy:

Settings

JPA Buddy provides flexible settings to make the use of coding assistance features even more handful. You can:

  1. Enable/disable automatic detection for the bean injection type;

  2. Define the bean injection strategy that JPA Buddy will follow while code generation;

  3. Configure whether to use the smart completion features or not.

settings-coding-assistance
Last modified: 14 March 2024