Question

when using ehcache rather than defining statement like

 <cache name="testonly.package.model.TestPOJOcategory"
        maxElementsInMemory="200"
        eternal="true"
        overflowToDisk="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
    />

can directly define inside entity independent of whatever cache provider we using?

@Cache(
  type=CacheType.SOFT, 
  size=64000 
  expiry=36000000,  
  coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS 
)

reference: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching (it only showed for EclipseLink, not ehcache)

Was it helpful?

Solution

First, even if most JPA persistence providers (like Hibernate, EclipseLink,...) provide support for second level cache(s), JPA 1.0 did not specify support of a second level cache. So, when playing with L2 cache, you are actually using JPA extensions which are not standard and are not portable from one provider to another. Hibernate's @Cache annotation is not the same than EclipseLink's @Cache annotation and is not comparable with OpenJPA's @DataCache annotation. All these are different, they are proprietary. If you are using Hibernate (which is my understanding of your previous questions), you shouldn't look at EclipseLink proprietary things (or for your culture only but this question goes beyond culture if I may).

Second, what makes you think that EclipseLink's @Cache annotation has anything to do with EHCache? AFAIK, EclipseLink uses its own cache implementation which is not related to EHCache.

Actually, I have the feeling that you are a bit lost here. You should maybe slow down a bit and do things step after step: choose one solution, stick with it, identify what you have to do, implements things one by one, and get the whole thing working. Focus on your goal, stop gathering more information for now, take some time to digest the new things you've learned.

OTHER TIPS

As far as I know in Hibernate we have something like this,

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TestPOJOcategory {
...
}

This annotation has two more attributes, region and include. To set the size, expiry and all those things, I am not aware of anything. You should consider the docs of EhCache, I believe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top