Using Custom Converter In Hibernate

Using Custom Converter In Hibernate

Overview Imagine this scenario, you have a legacy database that store weather data. The previous developer, due to various reason, store the temperature in the following format: id location temperature capture_date 1 Hanoi 30.50 C 2023-07-31 22:10:30.000 2 New York 95.20 F 2023-07-31 22:10:30.000 As you can see, the temperature stored in a sub-optimal way … Read more

Using @ColumnTransformer In Hibernate

Using @ColumnTransformer In Hibernate

Overview One of the lesser-known yet powerful annotations in Hibernate is @ColumnTransformer. This annotation let us apply SQL transformations on entity properties when interacting with the database. You can think of this annotation as a two way converter. A real life use case Let’s consider a weather app that initially use Kelvin scale to store … Read more

How To use @Formula in Hibernate

How To use @Formula in Hibernate

Overview From the official documentation, a Formula mapping defines a “derived” attribute (that means, not persisted), whose state is determined from other columns and functions when an entity is read from the database. You’d probably know other annotation that make a field not persisted to the database: @Transient. While they both allow you to create … Read more

Why does Hibernate Need A No-arg constructor

Why does Hibernate Need A No-arg constructor

Overview In this post, we are going to explore the reasons why does Hibernate need a no-arg constructor. The no-arg constructor need to be protected or public. A primer on the no-arg constructor When you declare a class without any constructor, the compiler create a default no-arg constructor for you. However, when you define constructor(s) … Read more