April 28, 2021

What’s New in JPA Buddy 3.0

JPA Buddy 3.0 is out! Support for Flyway script generation and Kotlin are finally here, along with other improvements and fixes. Let’s take a closer look at what it offers.

Flyway

Flyway support was one of the most requested features and we are happy to announce that it is finally available.

Flyway versioned migrations can be generated by

  • Finding difference between JPA entities and the database
  • Comparing two databases representing current and legacy states
    Take a look at how easy you can generate Flyway versioned migration with JPA Buddy by comparing your data model with the database you would like to update:

Migration files naming is another topic covered by JPA Buddy. There are a number of settings making naming as flexible as possible. You can define migration prefix, version pattern, separator and description. Learn more about migration naming in the Flyway documentation.
The version pattern can be selected from a number of commonly-used presets, or you may define your own version pattern using the following macros:

  • #date([format]) – the current system date in the specified SimpleDateFormat.
  • #increment([start], [step], [decimalFormat]) – a number that is used to keep the name unique.
  • semVer – semantic version of the project (also known as SemVer).

image1.png

You can read more about available variables and macros on our plugin page.

Kotlin (alpha phase)

Kotlin support is finally coming to JPA Buddy. Apart from a handful of inspections, it has the same feature set as Java: visual designers for entities and repositories, equals()/hashCode()/toString() generation, Hibernate Custom Types and JPA Converters, entity tree in JPA structure and many other things.

For example, here is how to create an attribute with JPA Palette and JPA Inspector:

For repositories, both the derived and @Query methods are supported:

Important: Kotlin is very flexible. It gives freedom to code the same thing in various ways. This is great for Kotlin developers, however, it is a significant headache in terms of development tools. We tried to support most common use cases for Kotlin use in JPA entities and Spring Data repositories. Obviously, there are many cases that we didn't consider, hence, couldn't test. If you use Kotlin, please, report all errors you get. Issues with Kotlin support will be at top priority for the upcoming minor releases.

Async methods in Spring Data repositories

Async options have been added to the query generation dialogs and to JPA Inspector:

Unidirectional OneToMany with JoinColumn

JPA supports unidirectional OneToMany associations which are represented only in the owning entity. One way to achieve this is to annotate the association with @JoinColumn:

@Entity
public class Customer {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "ID", nullable = false)
   private Long id;

   @OneToMany
   @JoinColumn(name = "CUST_ID") // this column is located in the ORDER_ table
   private Collection<Order> orders = new ArrayList<>();
}

The “CUST_ID” column is created in the “ORDER_” table, but it is not mapped to an inverse attribute in the Order entity:

@Entity
@Table(name = "ORDER_")
public class Order {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "ID", nullable = false)
   private Long id;

   // NOTHING about Customer
}

JPA Buddy now supports generating such associations, just check the “Owning side” box in the creation dialog:

Error reporting with Sentry

Bugs and errors are unavoidable in any software, development tools are no exception. We do our best to catch and fix as many as we can, but some do slip through. If you happen to find any yourself, please let us know via our contact form or in our Discord channel. It will really help to make JPA Buddy better.

We have also added a mechanism for reporting exceptions directly to us, now it’s as simple as clicking a button:

Conclusion

JPA Buddy keeps evolving, these are just some of the improvements it got in the 3.0 release. Many of them were suggested by our community, and we want to encourage you to join our Discord channel to share your ideas and feedback.