Eclipselink 缓存和 Session 对象

Eclipselink cache and Session object

我们通过设置

禁用了缓存
eclipselink.cache.shared.default=false

但此更改导致 ReadAllQuery 失败并显示消息

org.eclipse.persistence.exceptions.QueryException
Exception Description: Queries on isolated classes, or queries set to use exclusive connections, must not be executed on a ServerSession or, in CMP, outside of a transaction.

失败的查询是

entityManager.unwrap(Session.class).executeQuery(readAllQuery);

我试过设置以下参数

eclipselink.query-results-cache=false
eclipselink.refresh=true

还是出现同样的异常。有人可以帮忙解决这个问题吗?

1) 禁用 JPA 缓存并确保所有查询都进入数据库(以确保所有计算机之间的数据一致性)的最佳方法是什么。所有write/update/read都应该作用于数据库对象,并且应该是一致的。

2) 我们可以接受所有查询访问数据库的性能开销

您正在使用的 API 为您提供共享 serverSession,您不应将其用于查询,因为您已禁用共享缓存。相反,您需要支持 EntityManager 的 UnitOfWork,因为这将为该上下文维护缓存和对象。

entityManager.unwrap(UnitOfWork.class).executeQuery(readAllQuery);