Get a list of managed Entity instances in the persistence context

Is there a way to get a list of “known” Entity instances for a given Session / EntityManager in JPA / Hibernate 4.x?

By "known" is meant either loaded, created or modified, i.e. A managed entity that exists in the context of persistence. I know the method EntityManager#contains, so I assume that such a list is supported, but how can I get to it?

EDIT: Also, how can I query the state of a persistent entity (check if it is created, updated, deleted, or cleared in this persistence context)?

+4
source share
1 answer

JPA ​​. , Hibernate:

final org.hibernate.engine.spi.SessionImplementor session = em.unwrap( org.hibernate.engine.spi.SessionImplementor.class );
final org.hibernate.engine.spi.PersistenceContext pc = session.getPersistenceContext();
final Map.Entry<Object,org.hibernate.engine.spi.EntityEntry>[] entityEntries = pc.reentrantSafeEntityEntries();

entityEntries Map.Entry, "" - org.hibernate.engine.spi.EntityEntry, , , ​​ EntityEntry.getStatus().

+5

All Articles