gpt4 book ai didi

java - 通过entityManager.refresh刷新实体集合(getResultList)

转载 作者:行者123 更新时间:2023-12-01 07:15:44 26 4
gpt4 key购买 nike

启用 JPA 缓存时如何刷新实体的 getResultList 集合。我的意思是:

列出客户 = query.getResultList();

???? > em.refresh(客户)!//我需要刷新,因为缓存已启用。

RGDS纳维德

最佳答案

在 JPA 2.0 中,通过使用查询提示完全跳过 L2 缓存可能会更容易。例如:

Query query = em.createQuery(...); 
query.setHint("javax.persistence.cache.retrieveMode", "BYPASS"); // skip the L2 cache.
List customers = query.getResultList();

但这在 JPA 1.0 中不可用。如果您使用的是 JPA 1.0,您可能必须使用供应商特定的 API。我相信 Hibernate 提供了类似于 JPA 2.0 提示的东西(其他提供商也可能有这种机制)。 OpenJPA 有一个refreshAll(Collection c)方法也应该适合你,我怀疑其他提供商也有类似的东西。不过 EclipseLink 似乎没有。

关于java - 通过entityManager.refresh刷新实体集合(getResultList),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3204592/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com