public PersistenceUnitUtil getPersistenceUnitUtil();
The EntityManagerFactory method
getPersistenceUnitUtil provides access to a
PersistenceUnitUtil utility. PersistenceUnitUtil
can be used to obtain the identity of a managed object and determine the load
state of the entity or one of its attributes. If the object is not
managed by one of the entity managers created from the entity manager factory
from which the utility was obtained, the getIdentifier method will
return null and the isLoaded methods will return false.
EntityManagerFactory emf = Persistence.createEntityManagerFactory();
PersistenceUnitUtil puUtil = emf.getPersistenceUnitUtil();
if (puUtil.getIdentifier(deptEntity) == null) {
throw new Exception("Identity is not valid.");
}
if (!puUtil.isLoaded(deptEntity, "employees")) {
throw new Exception("Employees not loaded.");
}