liveBook · Manning

Runtime proxy generation

As explained in Java Persistence with Spring Data and Hibernate epub

Runtime proxy generation is the creation of proxy classes during program execution to intercept or defer access to entity state.

Runtime proxy generation creates Hibernate proxy classes during execution to defer loading entity associations. The domain classes need no special supertype, bytecode post-processing, or build-time code generation. section 12.1.1

Use proxies with these lifecycle and modeling constraints:

  • Avoid assuming proxy classes equal entity classes, direct field access in equals() or hashCode(), or lazy loading for basic and embedded properties. section 12.1.1

Persisting a bid without loading referenced entities

Obtain Item and User with em.getReference(), assign them to a new Bid, and call em.persist(). Hibernate can queue the BID INSERT using proxy identifiers without issuing SELECT statements.

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains proxy identity, initialization, persistence-context behavior, and limitations, but stops short of basic-property lazy loading.
Examples
Uses Item, User, and Bid entities to demonstrate getReference(), lazy seller loading, explicit initialization, and identifier-only insertion.
What it assumes
Assumes entity associations and persistence-context operations, while demonstrating proxy initialization and loaded-state inspection.
What you can do after
Apply Hibernate proxies to defer association loading and persist references without fetching their entity data.
How it connects
Connects lazy loading with persistence contexts, entity associations, polymorphic associations, and equality and hashing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.