Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
In this article, Manika Singh shows 7 mistakes you should avoid when using JPA and Hibernate.
If you want to execute a custom SQL function from a JPQL or Criteria API query,
it’s best to register the function so that Hibernate knows how to pass arguments and map the return value.
This article explains how you can
register an SQL function which can take parameters from the executing
Query or reference the underlying
table columns via the entity properties in the JPQL query.
This article explains the difference between the JPA standard and the Hibernate framework which implements the Java Persistence specification.
If you’re using PostgreSQL and want to map Java Enums to the PostgreSQL-specific Enum types, this article explains how you can do that without even having to write a new custom Hibernate Type.
For our Portuguese readers, this article explains what the N+1 query issue is and how you can overcome it when using JPA and Hibernate.
org.hibernate.Hibernate utility class defines an
initialize method which takes an entity or a collection
proxy and forces the proxy initialization. However, this is only useful if the proxy can be fetched from the second-level cache. If the proxy initialization triggers a database query, then it’s much more efficient
to simply fetch the lazy association with the initial database query.
For more details, check out
Debezium is an open-source framework which allows you to extract CDC (Change Data Capture) events from the database log and consume them either via an embeddable driver or using Kafka. This article explains how you can use Debezium to detect database changes that happen outside of Hibernate and invalidate the second-level cache entries associated with the recently changed table rows.
Hibernate is a very customizable framework, and because you can override the default CRUD statements, it’s very easy to implement a soft delete mechanism which allows you to retain deleted entities in the database, but to hide them in the application after they were logically deleted. This article shows you got to exclude deleted entities from a given association.
Time to upgrade
There were two releases for the Hibernate ORM project:
Hibernate ORM 5.4.0 CR2 is the second release candidate for the 5.4 branch. We are looking forward to getting your feedback for this release.
The Hibernate ORM 5.1.17 release provides bug fixes and improvements for the 5.1 branch. If you are using Hibernate ORM 5.1, you should upgrade to benefit from the latest enhancements.
There were two releases for Hibernate Search project as well:
Hibernate Search 6.0.0 Aplha1 is the first release for the 6th major version of this project. Although this version is not suitable for production due to its limitations and to the fact APIs are still unstable, it’s a great way to get a feeling of where Hibernate Search is going and provide your feedback.
Hibernate Search 5.11.0 CR1 is the first candidate release for the 5.11 branch, and it mainly includes an upgrade to Hibernate ORM 5.4.0.CR2.
Questions and answers
What is the solution for the N+1 issue in JPA and Hibernate?
How to avoid initializing a Hibernate proxy when only the entity id is needed
What Phenomena does MySQL try to prevent by locking the whole table upon executing Delete statement with the condition on a non-indexed column
What is the JPQL equivalent of the PostgreSQL date_trunc('day', (entity.date AT TIME ZONE 'UTC')) function when using JPA and Hibernate
What is the relationship between DTO and lazy-loading in Hibernate
MySQL Repeatable Read isolation level and Lost Update phenomena
Is the Java Hibernate framework archaic and obsolete in the age of NoSQL storage technologies?
DTO Projection: Hibernate expects a constructor although a resultTransformer AliasToBean is set
How to synchronize data when using multiple nodes for the Hibernate second-level cache
Is there a way to let Hibernate handle removal of an entry in a @ManyToMany association if I remove an entity not managing this association?
How to order columns alphabetically when creating a database table with Hibernate
How to use two different Hibernate caching strategies for a couple of entities
Mapping Java boolean to Oracle Number column with JPA and Hibernate