4 Database access with Panache

 

This chapter covers

  • What Panache is
  • Simplifying JPA development with Panache
  • Database testing with Panache and @QuarkusTest

In chapter 2, we created the Account service to show how to develop JAX-RS endpoints with Quarkus. In this chapter, we take that Account service and add database storage for the account data, instead of the data being held only in memory.

Because most microservices will need to store some type of data, or interact with data stored by another microservice, being able to read and store data to a database is a key feature to learn and understand. Though stateless microservices are “a thing,” and certainly a goal, if appropriate, for a microservice, there are also times when denying the need to store data leads to unnecessary mental gymnastics, leading to a significantly more complex distributed system.

To simplify the development of microservices requiring storage, Quarkus created Hibernate ORM with Panache (Panache), an opinionated means of storing and retrieving state from a database, heavily inspired by the Play framework, Ruby on Rails, and JPA experience. Panache offers two different paths, depending on developer preference: active record and data repository. The data repository approach will be familiar to those with experience in Spring Data JPA.

4.1 Data sources

4.2 JPA

4.3 Simplifying database development

4.3.1 Active record approach

4.3.2 Data repository approach

4.3.3 Which approach to use?

4.4 Deployment to Kubernetes

4.4.1 Deploying PostgreSQL

4.4.2 Package and deploy

Summary