遵循我的代码:
Company cc = em.find(Company.class, clientUser.getCompany().getId());
System.out.println(cc.getCompany_code());
HashMap findProperties = new HashMap();
findProperties.put(QueryHints.CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS);
Company oo = em.find(Company.class, clientUser.getCompany().getId(), findProperties);
System.out.println(oo.getCompany_code());就像示例“用作EntityManager属性”一样。here
但是,这两个输出之间没有什么不同。
发布于 2010-12-17 21:57:24
你期望什么是不同的?为什么?
请注意,CACHE_RETRIEVE_MODE仅影响共享(二级)缓存,而不影响持久性上下文(一级缓存/事务性缓存),因此必须始终在已读取的对象的持久性上下文中维护对象身份。
如果您已经更改了数据库,并且需要新的数据,那么可以尝试使用新的EntityManager绕过它,或者尝试使用refresh()。
EclipseLink还提供了查询提示"eclipselink.maintain-cache"="false“来绕过持久性上下文。
您使用的是什么版本的EclipseLink?我相信在2.1中修复的2.0版本中有一个绕过的bug。尝试最新版本。
https://stackoverflow.com/questions/4462340
复制相似问题