0

我想看看 EclipseLink 的隔离缓存(L1 缓存)中存储了哪些对象。有没有让我这样做的 API?我尝试了谷歌,但找不到任何东西。

如果您对它的原因感兴趣,因为我发现在持久性上下文中加载一些对象后,查询会变慢,例如,在事务开始时需要 100 毫秒的查询现在如果在在其他一些操作已经发生之后的事务中间。如果我entityManager.clear()在查询执行之前这样做,查询再次需要 100 毫秒。我相信这是因为持久性上下文中加载了许多影响 EclipseLink 性能的对象。这就是为什么我想验证持久性上下文中的对象。

4

1 回答 1

0

在浏览了 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);
于 2012-12-29T00:16:00.370 回答