Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
Articles
When fetching parent entities along with their child associations, Hibernate applies the root-level pagination in-memory while the SQL query fetches all the data matching the provided filtering criteria. When paginating entity results in-memory, Hibernate issues the following warning message in the application log:
HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
However, if the number of parent and child records is large, it’s much more efficient to apply SQL-level pagination. This article explains how to limit the number of parent entities that are fetched along with their associated child records.
By default, Hibernate loads all entity properties when fetching an entity, and this might not be very efficient if you have Blob/Clob or large columns.
For this purpose, Hibernate offers the bytecode enhancement mechanism which can be configured to load entity attributes lazily.
This article provides more details about the enableLazyInitialization
bytecode enhancement mode.
When logging SQL statements, it’s very useful to print the underlying database transaction id so you can later aggregate the SQL statements by their associated transaction id. This article shows you how you can fetch the database transaction id when using Oracle, SQL Server, PostgreSQL, and MySQL.
To help you find the source of an issue, Hibernate provides context-specific exceptions. This article provides a comprehensive list of exception types that can be thrown by Hibernate as well as how you can overcome the underlying problem that triggered each exception.
The entity identifier can be either manually assigned or generated automatically. For the auto-generated entity identifiers, you can choose an auto-incremented numeric column or a UUID. If you want to use a UUID identifier, this article explains how to optimize the generated SQL statements when persisting the entity using Spring Data Repositories.
If you want to map an entity whose Primary Key is formed out of multiple columns, you need to use a composite identifier.
This article demonstrates how you can achieve this goal
using the Hibernate-specific multiple @Id
mapping.
When using JPA and Hibernate, the link table of a many-to-many table relationship is hidden at the entity modeling level, as only the parent sides need to be mapped. This article shows you how to map a many-to-many relationship with JPA, Hibernate and Spring Boot.
Questions and answers
-
How to synchronize the Hibernate second-level cache with the database across multiple JVMs
-
Hibernate issuing individual insert statements, even though batch insert is enabled
-
Configure Log4j 2 to store the logging information in a database table using Hibernate
-
Hibernate N+1 query issue when fetching @OneToOne associations with JPA Criteria and @LazyToOne
-
Can no longer use @MappedSuperclass and @Inheritance annotations in Hibernate 5.4
-
How to update a Timestamp property when only some entity fields get modified with JPA and Hibernate
-
How to get the Oracle transaction id of the transaction that caused a trigger
-
How to set SQL Server options (ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS) using Hibernate
-
Why does Hibernate execute 2 SQL query when using a PESSIMISTIC_WRITE LockMode on a JPQL query?
-
Rollback does not work with MyISAM storage engine with Hibernate and MySQL