2012-01-20 56 views
0

我正在使用Eclipselink JPA(2.0)。我需要訪問entityManagerFactory來清除所有緩存,因爲普通屬性設置或刷新或設置提示對我無效。我已經找到一種方法,從這段代碼做到這一點:如何從Eclipselink的EntityManager中訪問EntityManagerFactory

entityManager.getEntityManagerFactory().getCache().evictAll(); 

但是有)中的EclipseLink的EntityManager稱爲getEntityManagerFactory(沒有這樣的方法。我該怎麼做?

我正在使用Spring Bean配置EntityManagerFactory和entityManager註釋與@PersistenceContext在DAO層。

在Spring bean的配置:

<bean id="entityManagerFactory" 
     class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> 
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" /> 
<property name="jpaDialect" ref="jpaDialect" /> 
<property name="persistenceUnitName" value="MyService" /> 
</bean> 

在DAO:

private EntityManager entityManager; 

@PersistenceContext 
public void setEntityManager(EntityManager entityManager) { 
    this.entityManager = entityManager; 
} 

感謝。

+0

JPA 2供應商與您列出的方法的可用性無關,因爲它們都使用相同的接口。請發佈相關代碼,以便我們可以診斷真正的問題。 – Perception

+0

使用源代碼進行編輯,請檢查它。 – popcoder

+0

你使用的是什麼版本的Spring?請記住,如果您想要良好的JPA 2支持,您應該使用3.0版本。 – Perception

回答

相關問題