簡體   English   中英

重新加載持久實體

[英]Reloading of persisted entity

我作為JPA供應商在我的應用程序中使用OpenJPA。

這個問題是理論上還是概念上的:

有什么方法可以告訴實體管理器從數據庫而不是從緩存中加載實體?

問題場景:

EM1.persist(Entity1)
EM2.merge(Entity1)
EM1.find(Entity1)  <--- Entity1 is the cached version rather than the merged one..

有什么優雅的方法嗎? 我真的不想調用em.refresh(entity)

如果您有可用的實體,則em.refresh(entity)是強制重新加載該實體的最簡潔的方法。

如果您沒有可用的實體,可以致電:

EM1.clear(); // all entities are detached - might not be desired.  
EM1.find(Entity1);

在JPA 2.0中,您還可以顯式分離實體(但我不認為這比em.refresh()更好):

EM1.detach(Entity); 
EM1.find(Entity1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM