Getting started with quarkus and panache
Tags: quarkus, panache
Published: 2020-04-10 13:20:56

---
title: Getting started with quarkus and panache
published: true
description: 
tags: [quarkus, panache]
---

[Quarkus](https://quarkus.io/) is an open source framework, that uses well stabilished java libraries like hibernate, and adds something extra to them. 

Having a solid background in projects using J2EE and JEE (or now JakartaEE), I wanted to see how easy it would be to setup a project and having a simple crud application running. And also, since I am so familiar with application servers, is there any benefit in using quarkus? Wouldn't it be the same as using the application server?

One of quarkus' features is the ability to run on graalvm. I didn't test this here. It is a test for another day.
All the code is available on [github](https://github.com/kgoedert/quarkus-panache).

## First Impressions

My first impression was very good. There is a lot of simple tutorials to get you started. And the code on it, worked. It seems to have a lot of extensions based on well known frameworks and libraries which is also very good. Looking at the github repo it seems to be very active.

## Setup 

Very easy to get started. You basically need java 8+, maven 3.6.2+ and graalvm(if you want the native compilation).

You can follow their getting started guide [here](https://quarkus.io/guides/getting-started).

For my test I also added the extensions for hibernate orm, panache, postgres driver and liquibase.

## Development experience

The boot time is really fast. I boot it in development mode, a debug port is available. The hot reload worked pretty well. So I see this as an advantage over the application server. Even if the servers these days boot really fast, quarkus was faster.

With panache they added a nice layer on top of hibernate, that has a lot of cool features on building queries. I myself never liked the criteria api. Over the years other libraries like querydsl, that seems abandoned now, and deltaspike data tried to accomplish this query writing functionality. 

It also implements two patterns the repository pattern, and the active record pattern. Both work, but in this test I chose to go with the repository pattern, that I seem to use more frequently.

One thing I did not like, was that the panache API encapsulated methods like persist and delete, but not merge. To be able to do a merge I had to create a method that would set every attribute.

```
@PUT
@Path("/{id}")
@Transactional
 public Response update(@PathParam("id") Long id, Movie movie) {
    if (this.isValid(movie, id)) {
        Movie m = movieRepo.findById(id);
        if(m == null){
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        m.update(movie);
        return Response.status(Status.OK).entity(movie).build();
    } else {
        return Response.status(Status.BAD_REQUEST).entity("Movie already exists").build();
    }
}
```

```
public void update(Movie updated) {
    this.director = updated.getDirector();
    this.genre = updated.getGenre();
    this.title = updated.getTitle();
  }
```

Another thing that I don't really quite like is to have the attributes as public or default on classes. Having them public makes the serialization easier, and the framework allows you to create your regular getters and setters, and if you do, it will use them.

But I still prefer to have them private, and create getters and setters only if I need them. So, I created a JsonbConfigCustomizer, and was able to use the entities the way I wanted.

```
@Singleton
public class JsonConfigurator implements JsonbConfigCustomizer {
    public void customize(JsonbConfig config) {
        config.withPropertyVisibilityStrategy(new PrivateVisibilityStrategy());
    }
}

```

The liquibase integration also worked really well. Had no issues here, every worked as it usually does.

## Conclusion

I liked the framework and the experience of using it overall. I will test other features as soon as possible. If anyone has experience using it on a production environment I would like to hear about it.
Would I try it in production? Yes, after testing the other extensions that would be needed for the project. 
If you have experience in the JEE/JakartaEE stack, it is really easy to pick up.