开发者

Reloading of persisted entity

I'm using OpenJPA in my app开发者_StackOverflow中文版lication as a JPA vendor.

The question is theoretical or conceptual:

Is there any way to tell an entity manager to load an entity from the DB rather than from it's cache?

The problematic scenario:

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

Any elegant way to do it? I really don't want to call em.refresh(entity).


If you have the entity available then em.refresh(entity) is the cleanest way to force the entity to be reloaded.

If you don't have the entity available you can call:

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

In JPA 2.0 you could also explicitly detach the entity (but I don't see this as being better than em.refresh()):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜