Coffee with Thorben 2020-02-19 – Enums, Enums, Enums …

Take your skills to the next level!

The Persistence Hub is the place to be for every Java developer. It gives you access to all my premium video courses, 2 monthly Q&A calls, monthly coding challenges, a community of like-minded developers, and regular expert sessions.

Follow me on YouTube to not miss any new videos.

Join the chat on YouTube.

Enums, Enums, Enums …

Enums are the perfect data type, if an attribute can only have one out of a set of predefined values. A typical example is the rating of a product, which can have the values 1, 2, 3, 4 and 5.

Using JPA’s default mappings, you can persist an enum value as a String or as its ordinal value. In addition to that, we can provide our own mappings using JPA’s standard types or implement a custom type that supports database-specific enum types.

In today’s stream, we will take a look at all 4 options and discuss when you should use which of them. If you want to dive deeper into this topic, I recommend the following articles:

Live Online Workshops

If you enjoyed the live stream, you will love my live online workshops. Find out more at

Question of the Week

Ajay asked this week’s question of the week in the comments of one of my recent YouTube videos about DTO projections. He wanted to know if there is any support for nested DTO projections.

This week’s tutorials


Refactoring the persistence layer is the most critical part when splitting a monolith into microservices. You need to make the services as independent as possible while also ensuring data consistency and providing great performance.

In this week’s post, I explained the general steps to split up a monolith, some of the patterns you should know to solve common problems, and when you should rethink your design decisions.

Find out more at From Monolith to Microservices – Migrating a Persistence Layer.


Using JPA and Hibernate, you can map a Collection in various ways. One option is to map them as an association to another entity class. Or, if you don’t want to model another class, you can use an @ElementCollection or as your own basic type.

I explain all 3 options with their advantages and disadvantages in this week’s video:

Follow me on YouTube to not miss any new videos.

Related Articles


Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.