Loading...

Letzte Beiträge

JPA 28. Juni 2023

Wie definiere ich einen Index mit Spring Data JPA

In diesem Artikel beschäftigen wir uns mit der Definition von Indizes in Spring Data JPA und dem Hibernate Framework. Unser Fokus liegt dabei auf der Definition eines Indexes für eine Nicht-Primarykey und der Nutzung der @Index Annotation. Die richtige Verwendung von Indizes spielt eine entscheidende Rolle für die Leistungsoptimierung deiner Datenbank, da sie schnellere Datenabfragen ermöglicht und insgesamt die Datenbankperformance verbessert. Definition eines Indexes mit der @Index Annotation Mit JPA und Hibernate kannst du Indizes auf Entitäten und Nicht-Entitätstabellen wie @SecondaryTable, @CollectionTable und @JoinTable über die @Index Annotation definieren.


JPA 21. Januar 2023

Accessing Non-Final Property Name in Constructor With JPA

The implications of JPA always manage to surprise me. Yesterday a colleague of mine made me aware of a warning in IntelliJ. The conversation went like that: “Marcus, in your blog you explained that we should check constraints in the constructor instead of bean validation . Me: “yeah”. “I wanted to make it right, but when I do it in this entity IntelliJ warns me with Accessing non-final property name in constructor”.


JPA 2. August 2021

Prefer UUID for your Primary Key

In my last post I discussed the downsides of using numerical types for the primary key of an entity. We should avoid these issues all together by using UUID instead and in this post I will discuss the up- and downsides of this approach. Using a UUID as the primary ID is simple: @Entity class Flat( @Id val id: UUID = UUID.randomUUID() ) Generate the ID on the application Similar to numerical ids we can generate it on the database as well.


JPA 15. Juli 2021

The Inevitable Consequence of a Numerical Id

In many (JPA) applications numerical ids are chosen for the surrogate key of the entities. But how do we make sure that they are not used twice? In a scenario where our application needs to scale horizontally we need a solution for that. Most developers come to the conclusion that the database should take care of that. But this is a fragile solution and in this article I want to discuss it.


JPA 20. März 2021

Should I Pass JPA Entities as Method Parameters?

JPA entities have a couple of pitfalls and consequences when handling them in your application. Especially understanding how JPA manages and synchronizes the state of an entity is essential to avoid unexpected behavior. This can be unintuitive when passing JPA entities as method parameters in Spring Data in- and outside a transaction. In this post I will explain a best practice when working with JPA entities and when it’s okay to pass it through method parameters and when you should avoid it.


Top