Andrea Tasca Messages: 2 Registered: February 2013
Junior Member
Hi,
I need to clear cache on Eclipselink JPA 2.0.
As from documentation http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching
this can be done using the JPA Cache interface:
em.getEntityManagerFactory().getCache().evictAll();
but "the method getEntityManagerFactory() is undefined for the type EntityManager".
This is my code:
EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
em.getEntityManagerFactory().getCache().evictAll();
getEntityManagerFactory() exists on javax.persistence.EntityManager since JPA 2.0, so it means you are using a JPA 1.0 jar. Check your classpath and verify you have javax.persistence_2.0.3.v201010191057.jar (shipped with EclipseLink 2.3.2) ahead of or instead of the javax.persistence_1.0.0.jar.
Andrea Tasca Messages: 2 Registered: February 2013
Junior Member
Hi Chris you are right.
I had either javax.persistence_1.0.0.jar and javax.persistence_2.0.4.v201112161009.jar
in my classpath.
I've removed javax.persistence_1.0.0.jar and now it works.