How to map Java and SQL arrays with JPA and Hibernate

Introduction Hibernate custom Types allow you to map all sorts of database specific column types, like IP address, JSON columns, bit sets or SQL arrays. There are two ways to define a custom Hibernate Type: the UserType interface Java and SQL descriptors The latter option is preferred since it allows you to better split the Java-to-JDBC and the JDBC-to-SQL type handling. In this article, we are going to see how you can map SQL arrays to their Java counterpart.

How does MySQL result set streaming perform vs fetching the whole JDBC ResultSet at once

Introduction I read a very interesting article by KreŇ°imir Nesek regarding MySQL result set streaming when it comes to reducing memory usage. Mark Paluch, from Spring Data, asked if we could turn the MySQL result set streaming by default whenever we are using Query#stream or Query#scroll. That being said, the HHH-11260 issue was created, and I started working on it. During Peer Review, Steve Ebersole (Hibernate ORM team leader) and Sanne Grinovero (Hibernate Search Team Leader) expressed their concerns regarding making such a change. First of all, the MySQL result set streaming… Read More

The best way to map a Java 1.8 Optional entity attribute with JPA and Hibernate

Introduction StackOverflow is a neverending source of great questions. This time, we are covering this question about using Java 1.8 Optional with JPA and Hibernate. Java 1.8 introduced the java.util.Optional container object that may or may not contain a certain value. Combining Optional and streams is very handy. Therefore, you might want that some nullable entity attributes be exposed as Optional. This article is going to demonstrate what are caveats of using Optional with entity attributes, and how you can overcome them.

How to enable bytecode enhancement dirty checking in Hibernate

Introduction Hibernate runs the automatic dirty checking mechanism during flush-time, and any managed entity state change is translated into an UPDATE SQL statement. The default dirty checking mechanism uses Java reflection and goes through every property of every managed entity. If the Persistence Context has few entities, this process might go unnoticed, but, if we’re dealing with many entities or the entities have many properties (e.g. a legacy database Domain Model mapping), then the reflection-based dirty checking might have an associated performance impact.

How does FlexyPool support both Connection proxies and decorators

Proxies FlexyPool monitors connection pool usage and so it needs to intercept the connection close method call. For simplicity sake, the first version was relying on dynamic proxies for this purpose: As straightforward as it may be, a proxy invocation is slower than a decorator, which calls the target method using a direct invocation. Because all connection pools use proxies anyway, adding another proxy layer only adds more call-time overhead and so now FlexyPool supports connection decorators as well.

New Video Course