Spring

How to quickly create JPA Queries for nested properties

March 25, 2024
Spring, Spring Data JPA
JPA Queries, Repository Concept, Normalisation

Sometimes we may need to define some of entity’s fields and properties as embedded classes or records. As the information is still persisted at the entity level, there may be a need to query data using this embedded information. So how to quickly define a corresponding query method in a Spring Data JPA Repository? Example # Let’s take the following example: public class SomeEntity { private String someField; @Embedded private SomeValueObject someEmbeddedField; . ...

Using audit metadata in Spring Data JPA

March 19, 2024
Java, Spring, Spring Data JPA
Java, Spring Boot, Jpa

Introduction # While persisting objects there may be the need to save some extra generated information that the user does not need to care about but which is nevertheless relevant to some backend process or business need. In this article we explain how one can enable such information so that it is persisted along with the object state. Activation # In order to activate metadata recording in Spring Data JPA some configuration changes should be made: ...

Maps with Spring Data JPA

March 18, 2024
Java, Spring, Spring Data JPA
Java, Spring, Jpa

Introduction # This small article explores one way of using Maps for data modelling in a JPA (Java Persistence API) based application. Model # Imagine we have the following data model: classDiagram User "1" *-- "*" Account : manages This means: A user has one bank account per account type. Accounts do not need to be aware of their ‘owner’. We need to have access to all user accounts, preferably by account type. ...