永続性エンティティ マネージャーで第 2 レベルのキャッシュを削除しようとしています。javax.persistence.Cache インターフェイスで定義されている次の関数を使用できるようです。
/**
* Clear the cache.
*/
public void evictAll();
Cache オブジェクトを取得するには、javax.persistence.EntityManagerFactory インターフェイスで定義されている次の関数を使用できます。
/**
* Access the cache that is associated with the entity manager
* factory (the "second level cache").
* @return instance of the <code>Cache</code> interface
* @throws IllegalStateException if the entity manager factory
* has been closed
*
* @since Java Persistence 2.0
*/
public Cache getCache();
EntityManagerFactory を次のように配線します。
@Repository("persistenceManager")
public class PersistenceManager
{
public EntityManagerFactory emf;
@PersistenceUnit(unitName="snap")
public void setEntityManagerFactory(EntityManagerFactory emf) {
this.emf = emf;
...
}
次の applicationContext 構成ファイルを使用します。
< bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
< property name="persistenceUnitName" value="snap" />
< property name="persistenceUnitManager" ref="pum" />
オブジェクトで getCache() を呼び出すと、次の例外が発生します。
原因: java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerFactoryImpl.getCache()Ljavax/persistence/Cache; sun.reflect.NativeMethodAccessorImpl.invoke0 (ネイティブ メソッド) で.invoke(Method.java:597) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:376) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:517) com.sun.proxy.$Proxy26.getCache(不明なソース) com.rbccm.gelp.server.util.PersistenceManager.getCache(PersistenceManager.
これは、getCache (インターフェースで定義されている) が、EntityManagerFactory に接続されているオブジェクトに実際には実装されていないことを示しています。そのため、setEntityManagerFactory(EntityManagerFactory emf) に breakboint を配置すると、オブジェクトの具象型が実際には org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean であることに気付きました。
このクラスのソース コードを参照すると、ここで getCache() が実装されていないことが確認できます。正しい/互換性のあるバージョンを使用していると思います:
- 休止状態 3.6.10
- 春 3.1.1
- JPA2.0
誰かが同様の問題に遭遇したか、この問題を再現できますか? これに対処するにはどうすればよいですか?そうでない場合、第 2 レベルのキャッシュからすべてのキャッシュ アイテムを削除する代替手段は何ですか?