简体   繁体   English

逐出并包含在JPA中的Cache上

[英]Evict and contains on Cache in JPA

In JPA,if I have two entity classes Account and CheckingAccount,such that CheckingAccount extends Account.I have a CheckingAccount entity instance with primary key of 10. 在JPA中,如果我有两个实体类Account和CheckingAccount,则CheckingAccount扩展了Account。我有一个主键为10的CheckingAccount实体实例。

Cache c=//get a reference to caache from entity manager factory
c.evict(Account.class,10);
boolean flag1=c.contains(Account.class,10);
boolean flag2=c.contains(CheckingAccount.class,10);

will the value of both flags be false. 两个标志的值都将为false。

The first c.contains(Account.class,10) certainly will be false - you either have removed this entity from cache or it does not exist. 第一个c.contains(Account.class,10)当然是假的-您已经从缓存中删除了该实体,或者该实体不存在。

Second one c.contains(CheckingAccount.class,10) can be true if this entity has been put into cache. 如果此实体已放入缓存c.contains(CheckingAccount.class,10)第二个c.contains(CheckingAccount.class,10) 可以为true。

The version of evict method which takes second argument works only for given entity of given id. evict第二个参数的evict方法的版本仅适用于给定id的给定实体。 It is not the same as Cache#evict(Class) which removes all entities along with them subclasses from cache. 它与Cache#evict(Class) ,后者从高速缓存中删除所有实体及其子类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM