| Ko

JPA First-Level and Second-Level Cache

History and Concepts of Hibernate Cache Architecture Hibernate has included caching as a core performance feature since Gavin King first developed it in 2001. Since then, its cache architecture has evolved into a two-level hierarchy consisting of first-level and second-level cache, reducing database access and improving application performance. The first-level cache is a mandatory feature that has existed since Hibernate’s early versions alongside Session (now EntityManager). The persistence context itself serves as the first-level cache, guaranteeing entity identity within a transaction and providing the foundation for Dirty Checking. ...

June 8, 2024 · 9 min · 1767 words · In-Jun

Understanding JPA Persistence Context

Concept and History of Persistence Context The persistence context is the scope in which JPA manages entity instances. It is a core JPA concept that manages entity lifecycles between the application and the database while also providing several optimization features. This idea first appeared as Hibernate’s Session, introduced by Gavin King in 2001. Hibernate’s Session abstracted database access, tracked entity state, and maintained a consistent view of data within a transaction. When JPA 1.0 was introduced in 2006, the concept was standardized as the persistence context and EntityManager. ...

June 8, 2024 · 6 min · 1259 words · In-Jun

JPA Dirty Checking

Concept and History of Dirty Checking Dirty Checking is one of Hibernate’s core features. It automatically detects changes to entities managed by the persistence context and reflects those changes in the database. Gavin King introduced this mechanism when he first developed Hibernate in 2001 as part of the framework’s Transparent Persistence model. The goal was simple: let developers update the database by changing an object’s state, without writing explicit UPDATE statements. ...

June 8, 2024 · 7 min · 1436 words · In-Jun

Understanding the JPA N+1 Query Problem

What is the N+1 Problem? The N+1 problem is a common performance issue in Object-Relational Mapping (ORM) where N additional queries are executed when retrieving associated entities. As a result, the total number of queries becomes N+1. As the number of queries increases, database round trips increase, network latency grows, and the risk of database connection pool exhaustion rises, which can significantly degrade performance. History and Background of the N+1 Problem The N+1 problem emerged alongside ORM frameworks and is particularly common when using Lazy Loading strategies in Hibernate and JPA. ORM frameworks adopt lazy loading as the default strategy to handle data in an object-oriented manner by deferring the loading of associated entities until needed. This approach has advantages such as preventing unnecessary data loading and improving initial loading speed. However, when developers access associated entities inside loops without recognizing the relationships, individual queries are executed for each entity, causing the N+1 problem. It has been a persistent performance issue from the early versions of Hibernate to the present. ...

June 8, 2024 · 7 min · 1364 words · In-Jun

JPA Lazy Loading vs Eager Loading Performance

History and Necessity of Loading Strategies ORM (Object-Relational Mapping) frameworks emerged to solve the impedance mismatch between object-oriented programming and relational databases. During this process, how to efficiently load entities with associations became a critical challenge. Early ORM implementations used immediate loading for all associated entities, which caused performance degradation by loading unnecessary data into memory. Hibernate introduced a proxy-based lazy loading mechanism to solve this problem. Hibernate has continuously improved loading strategies since its initial release in 2001. While early versions only supported simple lazy loading, later versions added various optimization techniques such as fetch join, batch fetching, and subselect fetching. These features were included in the JPA (Java Persistence API) 1.0 standard when it was released in 2006. Through JPA 2.0 (2009) and JPA 2.1 (2013), declarative fetch strategies like @EntityGraph were added, enabling more sophisticated control over associated entity loading. Today, the JPA standard and Hibernate implementation continue to evolve together, providing developers with various options. ...

June 8, 2024 · 8 min · 1688 words · In-Jun

Understanding JPA Entity Lifecycle

What the Entity Lifecycle Is In JPA (Java Persistence API), the entity lifecycle describes the state changes an entity object goes through from creation to deletion. The concept was defined in the JPA 1.0 specification released with Java EE 5 in 2006, built around the persistence context and influenced by Hibernate’s Session model. Entities are classified into four states based on whether the persistence context manages them and how they are synchronized with the database: Transient, Managed, Detached, and Removed. They move between these states through EntityManager methods such as persist(), merge(), detach(), and remove(). ...

June 8, 2024 · 9 min · 1828 words · In-Jun

JPA EntityManager

History and Concept of EntityManager EntityManager is the core interface of the Java Persistence API (JPA), first defined in the EJB 3.0 specification released as part of JSR 220 in 2006. It was designed to standardize Hibernate’s Session interface and provide a vendor-independent persistence management API. The Session concept, introduced by Gavin King in 2001 during Hibernate’s development, was an innovative approach that abstracted database connections and tracked entity state. JPA standardized this idea, reformulated it as EntityManager, and enabled the same interface to be used across all JPA implementations (Hibernate, EclipseLink, OpenJPA). ...

June 7, 2024 · 8 min · 1574 words · In-Jun

Spring Data JPA vs. JPA Key Differences

JPA’s Origins and History JPA (Java Persistence API) was first announced on May 11, 2006, through Java Community Process JSR 220 as part of the EJB 3.0 specification. It standardized many of Hibernate’s core concepts to address the complexity, heavy structure, and container dependency of EJB 2.x Entity Beans. Those beans required a Home Interface, Remote Interface, and Bean Class, along with complex XML descriptors. That overhead hurt development productivity and made testing difficult. ...

June 7, 2024 · 8 min · 1607 words · In-Jun

Object-Relational Mapping (ORM)

History and Background of ORM ORM (Object-Relational Mapping) is a technology that automatically maps objects in object-oriented programming languages to tables in relational databases. It emerged in the early 1990s as object-oriented programming became mainstream and was designed to address the Object-Relational Impedance Mismatch between objects and tables. The first commercial ORM tool was TOPLink (now Oracle TopLink), released in 1994 for Smalltalk environments and later ported to Java in 1996. That helped spread ORM concepts throughout the enterprise Java ecosystem. ...

May 15, 2024 · 7 min · 1323 words · In-Jun
[email protected]