在瀏覽完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);