Loading...
Hot Topic

Anti-Pattern: Die perfekte Softwarearchitektur

Architecture
21. August 2024
Zum Post

Letzte Beiträge

JPA 7. Januar 2021

JPA Doesn't Call Persist But Merge Operation On New Entities

When working with JPA I prefer generating the primary key on the application and not in the database (check out this post from James Brundege ). Additionally, I also prefer optimistic locking and in order to use it you need to specify a @Version field in your Entity. But you need to be careful how to initialize these two fields. In this post I’ll talk about an error when you assign a default value for both fields in JPA which leads the EntityManager to never call persist but the merge operation instead when creating a new entity.


Clean Code 1. November 2020

Favor Polymorphism Over Enumerations

Last week I reviewed the data design of a colleague. He had to improve a feature and while working on it he noticed that the existing design was not sufficient to properly reflect the changes he had to do. Intuitive he followed the practices of other models in the code and introduced an enumeration to distinguish between different alert types that can be created in the application. Using an enumeration for it is not the optimal solution and in this post I want to describe why you should always question when you see an enumeration in your code and think about solving it with polymorphism instead.


Clean Code 14. Mai 2020

Avoid Inconsistent Builder With Lomboks @Builder

In a project I worked on I saw that nearly every entity and value object was created with Lomboks @Builder . Their reason is that it makes it easier to construct these objects - especially for tests. But it comes with a cost. The problems that these builders create can’t be detected by the compiler and are especially dangerous in every CI environment. Let’s look at an example. This is our object that uses the builder for construction:


Clean Code 6. März 2020

Best Practices For Unit Tests

Unit tests had a bad reputation in many teams I worked with. To my confusion I even experienced that a team wrote a hell lot of integration tests but rarely any unit tests. This is contrary to the well-known testing triangle, and surprised me quite a bit. The reason - as I was told - was the experience of the team. “When you change something you have to adapt many unit tests”, was the common tenor.


JPA 28. Januar 2020

Additional auditing with Spring Data JPA and Hibernate

Spring Data provides an easy way of keeping track who creates and modifies a persistent entity as well as when the action happened by annotating properties with @CreatedBy, @CreatedDate, @LastModifiedBy and @LastModifiedDate. The properties are automatically provided by an implementation of the AuditAware and DateTimeProvider interface. Beside this common auditing information in my current projects some entities require storing auditing-information about crucial state-changes like soft-deletion. Previously we had to fill the properties ourself:


Top