Layer 2 sleeping cache in orm.xml?

I have been working for several hours, I understand that users can use either an XML file (orm.xml, I suppose?), Or annotations in JPA, or both of them at the same time. I'm right? So, my project uses a second level cache that is not part of the JPA specification. And I use annotations like: @ org.hibernate.annotations.Cache (use = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)

for each object. However, I think the annotation above is not a JPA annotation, so I don’t know if there is anything equivalent in orm.xml? I looked at the xml orm.xml schema, and such a hibernate element is not allowed in the schema.

If I cannot configure the second level cache in orm.xml, is there any way other than in the annotation? The reason I don't want to do this is because I have two applications, one using the READ_WRITE concurrency strategy, and the other using the READ_ONLY concurrency strategy.

Thanks in advance!

Kewei

+4
source share
3 answers

So, I think the current solution to my problem is to replace all annotations of each object with Hibernate mapping files, so for different deployments (applications as well) we could use different Hibernate mapping files.

0
source

you can use hibernate.cfg.xml, hibernate.properties or * .hbm.xml files to enable caching for specific objects with different caching strategies.

+2
source

If you do not want to use annotations, check the documentation on the implementation of second-level caching of sleep mode (for example, "cache provider", for example ehcache ), how to configure it.

Note that Hibernate allows you to use different cache providers, so there is no general answer to your question.

+1
source

All Articles