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
