Persist LocalDateTime, ZonedDateTime & Co with Hibernate

Persist LocalDateTime, ZonedDateTime & Co with Hibernate

The Date and Time API, introduced in Java 8, finally replaced the old java.util.Date. It’s much easier to use and finally offers separate classes representing date, date with time, and only time information. That not only improves your business code but also makes it easier to use them as entity attributes. At least if you’re…

FetchType: Lazy/Eager loading for Hibernate & JPA
|

FetchType: Lazy/Eager loading for Hibernate & JPA

Choosing the right FetchType is one of the most important decisions when defining your entity mapping. It specifies when your JPA implementation, e.g., Hibernate, fetches associated entities from the database. You can choose between EAGER and LAZY loading. The first one fetches an association immediately, and the other only when you use it. I explain…

Logging Guide for Hibernate 4, 5 & 6 – Use the right config for dev and prod
|

Logging Guide for Hibernate 4, 5 & 6 – Use the right config for dev and prod

Choosing the right logging configuration can make the difference between finding a performance issue during development or suffering from it on production. But it can also create an overhead that slows down your application. You need to decide which information you need and configure your system accordingly. I, therefore, prefer to use two different configurations:…

JDBC Connection and Dialect Configuration in Hibernate
|

JDBC Connection and Dialect Configuration in Hibernate

To connect your persistence layer to your database, you need to configure a data source or provide the JDBC connection driver, URL, and login information to Hibernate directly. In addition to that, Hibernate needs to know the database-specific dialect it shall use to generate the SQL statements. Hibernate can detect the dialect based on the…