What is JPA Buddy?

Umakant
Introduction to JPA Buddy
4 min readJan 8, 2022

JPA Buddy is an IntelliJ IDEA plugin that helps with everything related to Jakarta Persistence API by providing development tools for Hibernate, Spring Data JPA, Liquibase, Flyway, SQL, etc. It is intended to make development faster.

What are the benefits of JPA Buddy?

Create JPA entities and data-related objects fast

  • Create JPA entities and data-related objects fast
  • Easily manage database migration
  • Make sure your code will not fail at runtime

JPA Buddy supports Java and Kotlin. You can use it in any project with Spring Boot, JavaEE (J2EE), Quarkus, Micronaut, or even without any framework.

What problem does it solve?

  • Usually, what we do we create our entities then again same we have to write scripts for our DB.
  • easy to miss something and typos.
  • So it reduces wastage of time

This tool reduces the developer’s efforts in data-centric applications.

To understand the working of JPA Buddy, develop a microservice using this without wasting too much time on writing boilerplate codes.

Step-1 First, we need to install the JPA Buddy plugin in our IntelliJ IDEA.

  1. cntr+alt+s
  2. plugins
JPA Buddy Plugin Installation

JPA Buddy Panel Structure

To understand the features of JPA Buddy we gonna create a demo project.

  1. Entity
  2. Repository
  3. Migration script

Let’s start to create a spring boot project.

We need the below-mentioned dependencies for our demo project.

  • Lombok
  • Spring Data JPA
  • Postgres driver
  • Spring data rest
  • Validator by hibernating
  • Flyway migration script

download the demo project and import it into the IntelliJ IDEA.

Here we can see the JPA structure

The first thing we need to make is a DB connection, to do that, We have to specify our DB credentials in the application. properties file.
Once we define the DB properties in the application.properties file, the JPA Buddy plugin is smart enough to identify the properties.

→application. properties

Usually, developers use two approaches for development

Usually, developers use two approaches for development

  1. DB-first: create the tables and then corresponding JPA entity
  2. JPA-first: create an entity first, then tables for it.

both ways have pros and cons so we can use them as per our requirement.

In our demo project, we will go with the entity approach.

Entity Creation

To create a new Entity, right-click on the desired folder and select New -> JPA -> Entity. In the opened window, you can:

  • Set class name
  • Define one of the following entity types:
  • Entity
  • Embeddable
  • Mapped Superclass
  • Select parent entity
Entity

Repository Creation

To create a new Repository, right-click on the desired folder and select New -> Spring Data -> Repository. In the opened window, you can:

  • Select the Model class.
Repository

Migration Script Generation

Next, We will create the migration script, using flyway.
first, we will add flyway dependency in pom.xml

<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>

Now to generate migration script,
Click on any model class ->New ->Flyway->Diff Versioned Migration.

Similarly, we can also create entity classes from DB scripts.

Conclusion.

  • JPA Buddy tool helps in the development and it reduces the chances of error.
  • We can create microservices in no time.
  • It reduces the efforts to generate SQL scripts or entities for SQL scripts.
  • JPA Buddy requires less configuration to work and it's easy to use.

--

--