CacheRetrieveMode.BYPASS of EclipseLink is not useful

陌路散爱 提交于 2019-12-30 12:14:48

问题


Follow my code:

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());

Just like the example "Used as EntityManager properties". here

But, there are nothing different between the two outputs.


回答1:


What are you expecting to be different and why?

Note that CACHE_RETRIEVE_MODE only affects the shared (2nd level) cache, not the persistence context (1st level cache/transactional cache), object identity must always be maintained in the persistence context for objects that have already been read.

If you have changed your database, and expect the new data then try the BYPASS using a new EntityManager, or try using refresh().

EclipseLink also provides the query hint "eclipselink.maintain-cache"="false" to bypass the persistence context as well.

What version of EclipseLink are you using? I believe there was a bug in BYPASS in the 2.0 release that was fixed in 2.1. Try the latest release.



来源:https://stackoverflow.com/questions/4462340/cacheretrievemode-bypass-of-eclipselink-is-not-useful

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!