在浏览了 EclipseLink 源代码后,我发现存储在持久性上下文(隔离缓存)中的对象位于一个名为 identityMaps 的映射中,对于每个实体类,都有一个映射存储该类型的所有对象。
您可以使用以下方法打印地图的内容:
public interface IdentityMapAccessor {
/**
* PUBLIC:
* Used to print all the Objects in the identity map of the given Class type.
* The output of this method will be logged to this session's SessionLog at SEVERE level.
*/
public void printIdentityMap(Class theClass);
/**
* PUBLIC:
* Used to print all the Objects in every identity map in this session.
* The output of this method will be logged to this session's SessionLog at SEVERE level.
*/
public void printIdentityMaps();
}
例子:
((JpaEntityManager) entityManager.getDelegate())
.getActiveSession()
.getIdentityMapAccessor()
.printIdentityMaps();
((JpaEntityManager) entityManager.getDelegate())
.getActiveSession()
.getIdentityMapAccessor()
.printIdentityMap(MyClass.class);