Using the LibCustom library, you can use Vavr functional data types such as List and Option with Hibernate 6.
This allows for cleaner code and null safety (no more using Java null).
The goal is to have entity model code looking like this:
To achieve this, we need to override some Spring data functions, using the LibCustom library.
First, add this dependecy to your pom.xml:
A good place to load the custom code is in the Spring config function:
Indeed this code is executed before the persistence layer instantiation.
You can find the whole DataSourceConfig code in my Github repo.
If you are not using Spring Boot, you can load the LibCustom code anywhere that will be executed before the Hibernate entities are loaded.
A good place generally is as a static code snippet in a config file of your application.
Thanks to this logic, you can enjoy concise functional code in your app.
Like for instance using List.map() without the whole .stream() and .collect() boilerplate code. For instance, when mapping a DTO to an Entity: