liveBook · Manning

PersistenceUtil

As explained in Java Persistence with Spring Data and Hibernate epub

PersistenceUtil is a JPA utility class that provides standardized static methods for inspecting the loading state of entities and persistent properties.

PersistenceUtil is a standardized JPA utility for inspecting whether an entity or one of its persistent properties has been loaded. Obtain the utility with Persistence.getPersistenceUtil(), then call isLoaded(entity) or isLoaded(entity, "property"). section 10.0 section 12.1.1

The checks are useful around lazy loading: an entity may be represented by a Hibernate proxy while an association remains an uninitialized proxy or collection wrapper. PersistenceUtil offers a portable alternative to Hibernate.isInitialized(). section 10.0 section 12.1.1

Inspecting an entity proxy

Item item = em.getReference(Item.class, ITEM_ID); PersistenceUtil persistenceUtil = Persistence.getPersistenceUtil(); assertFalse(persistenceUtil.isLoaded(item)); assertFalse(persistenceUtil.isLoaded(item, "seller")); The entity and its lazy seller association remain uninitialized until an operation requiring their data triggers loading. Calling item.getSeller() while evaluating another initialization check can itself initialize the item. section 12.1.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Defines entity and property checks with proxy examples, but stops short of implementing loading or detailing provider internals.
Examples
Uses an Item proxy, a lazy seller association, and assertions comparing entity and property initialization.
What it assumes
Assumes familiarity with JPA entities and persistence contexts while teaching proxy initialization checks from their practical behavior.
What you can do after
Diagnose/debug lazy-loading behavior by checking entity and association state without directly initializing the inspected object.
How it connects
Connects JPA persistence contexts, Hibernate proxies, lazy loading, fetch plans, and Hibernate.isInitialized().

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.