Wondering if any one has any suggestions on this
when i reload the page on my website i have a routine that calls a named query on one of my entities
@NamedQueries({ @NamedQuery(name = CatchUpBlockCMS.CATCHUP_BLOCK_BY_PAGEID,
query = "from CatchUpBlockCMS catchUpBlock where catchUpBlock.pageId = :pageId", cacheable = true,
readOnly = true, cacheRegion = CacheRegion.MEDIUM_QUERY) })
the cache on entity is set to
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = CacheRegion.MEDIUM_ENTITY)
so on each refresh the cache should return the result set from cache (btw level 2 cache is enabled on the app) first time it goes and loads two rows using the above query and they get cached up but if i go and remove a row from the db using another app and try to invoke the same query again it throws an entityNotFoundException on the missing row. Question is if it is cached shouldn't it just serve from the cache and return me stale data ...
the code for the entity is below
Code:
@NamedQueries({ @NamedQuery(name = CatchUpBlockCMS.CATCHUP_BLOCK_BY_PAGEID,
query = "from CatchUpBlockCMS catchUpBlock where catchUpBlock.pageId = :pageId", cacheable = true,
readOnly = true, cacheRegion = CacheRegion.MEDIUM_QUERY) })
@Entity
@org.hibernate.annotations.Entity(mutable = false)
@Table(name = "V_CATCHUP_BLOCK")
@Proxy(lazy = false)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = CacheRegion.MEDIUM_ENTITY)
public class CatchUpBlockCMS extends CatchUpBlock {
public static final String CATCHUP_BLOCK_BY_PAGEID = "query.CatchUpBlockCMS.byPageId";
private static final long serialVersionUID = 1L;
private long pageId;
private List<CatchUpProgrammeCMS> catchUpProgrammesCMS;
private FeaturedItemCMS featuredItemComponent;
@Override
@Id
@Column(name = "ID")
public long getId() {
return super.getId();
}
@Override
@Column(name = "CATCHUP_BLOCK_ID")
public long getCatchupBlockId() {
return super.getCatchupBlockId();
}
@Column(name = "PAGE_ID")
public long getPageId() {
return pageId;
}
public void setPageId(long pageId) {
this.pageId = pageId;
}
@Override
@Column(name = "CATCHUP_BLOCK_TITLE")
public String getTitle() {
return super.getTitle();
}
@Override
@Column(name = "DISPLAY_FEATURED_ITEM")
public Boolean isDisplayFeaturedItem() {
// check that the editor wants to display the featured item and that it is also valid
if ((super.isDisplayFeaturedItem()) != null) {
if (featuredItemComponent.isValid()) {
return true;
}
}
return false;
}
@OneToMany
@Immutable
@JoinColumn(name = "CATCHUP_BLOCK_ID", referencedColumnName = "CATCHUP_BLOCK_ID")
@NotFound(action = NotFoundAction.IGNORE)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = CacheRegion.MEDIUM_ENTITY)
@OrderBy(clause = "catchup_prog_order")
public List<CatchUpProgrammeCMS> getCatchUpProgrammesCMS() {
return catchUpProgrammesCMS;
}
public void setCatchUpProgrammesCMS(List<CatchUpProgrammeCMS> catchUpProgrammesCMS) {
this.catchUpProgrammesCMS = catchUpProgrammesCMS;
}
@Embedded
public FeaturedItemCMS getFeaturedItemComponent() {
return featuredItemComponent;
}
public void setFeaturedItemComponent(FeaturedItemCMS featuredItemComponent) {
this.featuredItemComponent = featuredItemComponent;
}
@Override
@Transient
public FeaturedItem getFeaturedItem() {
return featuredItemComponent;
}
@Transient
public void initialise(LocationResolver locationResolver) throws ReferredEntityNotFoundException {
if (featuredItemComponent != null) {
featuredItemComponent.initialise(locationResolver);
}
List<CatchUpProgrammeCMS> items = getCatchUpProgrammesCMS();
for (CatchUpProgrammeCMS item : items) {
getItems().add(item);
}
}
}
and this is the code that calls that entity
Code:
private void populateCatchUpBlock(HomePage page, long pageId) throws ReferredEntityNotFoundException {
Query q = entityManager.createNamedQuery(CatchUpBlockCMS.CATCHUP_BLOCK_BY_PAGEID);
q.setParameter("pageId", pageId);
List<CatchUpBlockCMS> catchUpBlock = null;
CatchUpBlockCMS block = null;
try{
catchUpBlock = q.getResultList();
}catch(EntityNotFoundException e){
logger.info("entity refreshed for page " + pageId);
}
if (catchUpBlock != null && catchUpBlock.size() > 0) {
block = catchUpBlock.get(0);
block.initialise(locationResolver);
}
page.setCatchUpBlock(block);
}
this is my cache config
Code:
<cache name="mediumEntity"
maxElementsInMemory="300000"
eternal="false"
timeToIdleSeconds="3000"
timeToLiveSeconds="3000"
overflowToDisk="true"
diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="210"
memoryStoreEvictionPolicy="LFU"/>
what am i doing wrong i dont want that exception to be throw i am happy with stale data until the cache refresh kicks in, how do i suppress that exception so i get served whats in the cache ?