Hibernate getReference(): When a SELECT is not needed at all
This article explores the classic N+1 query problem in Hibernate and methods for its optimization. The author notes that while JOIN FETCH and EntityGraph are standard tools for this task, developers often overlook the getReference() method (formerly load()). This method allows for obtaining an entity proxy object without executing a SELECT SQL query against the database, provided the object's identifier is already known. Using getReference() is effective in scenarios where it is necessary to establish relationships between entities or delete an object without loading its full data into memory. The article explains the mechanics of proxy objects, their performance benefits, and potential risks, such as LazyInitializationException. This material is useful for Java developers looking to optimize database interactions and reduce the load on the ORM layer in high-load applications.
This is a summary. Read the full article at the original source:
HabrRelated stories
One SoapFault — and the PHP garbage collector is disabled forever. A memory leak story
The authors share their experience investigating a mysterious memory leak in a PHP queue consumer that frequently crashed with an OOMKilled error. Alt…
REA: Let Your AI Agent Reverse Engineer the App Features You Wish You Had
REA is a new open-source tool designed to simplify the reverse engineering process by delegating tasks to AI coding agents. By functioning as both a C…
This tutorial provides a practical guide to building an AI-powered agent capable of analyzing SEC 10-K risk factor disclosures. Using TypeScript, the…


