0

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)

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

But the xml config provided in the question will not be necessary in case annotations are used. The only configuration needed is to configure EhCache, not which entity is using cache. I hope I clear your doubts.
2

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.

6 Comments

Is it compulsory to se config insie ehcache.xml with <cache name=entity.path... because if i commented that, it still works . can comment?
Of course, thats what you are telling through annotation. You should use either one. Using both means xml config is overriding the annotation thingie.
okie.. thanks for the clarrifying. article acupof.blogspot.com/2008/01/… … mentioned different thing, it stated, both must be specify @anotatino and configure the entity inside ehcache
@Vinegar Are you sure of this? I mean, configuring entity caching is one thing, but configuring the cache provider is another. One doesn't exclude the other.
I think cometta confused my answer with that blog post. So, cometta, you stick to the Pascal's advice, in the other post, and clear your understanding about what you already know.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.