views:

777

answers:

2

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)

+1  A: 

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.

Adeel Ansari
Is it compulsory to se config insie ehcache.xml with <cache name=entity.path... because if i commented that, it still works . can comment?
cometta
Of course, thats what you are telling through annotation. You should use either one. Using both means xml config is overriding the annotation thingie.
Adeel Ansari
okie.. thanks for the clarrifying. article http://acupof.blogspot.com/2008/01/background-hibernate-comes-with-three.html … mentioned different thing, it stated, both must be specify @anotatino and configure the entity inside ehcache
cometta
@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.
Pascal Thivent
But the xml config provided in the question is the configuration for a particular entity, not for the EhCache. Am I correct? So, I am talking about the same not about replacing the configuration for provider with this annotation. Of course it would be a silly idea. By th way, this annotation doesn't really look like that even in a glance.
Adeel Ansari
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.
Adeel Ansari
+2  A: 

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.

Pascal Thivent
@Pascal, thank you. very appreciated for your comment
cometta
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.
Adeel Ansari