Question

Having been googling for hours, I realize that users can use either xml file(orm.xml, I suppose?) or annotations in JPA, or both of them at the same time. I'm i correct? So, My project use the second-level cache, which is not in the JPA specification. And I use annotations like: @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE )

for each entities. However, I guess that the annotation above doesn't belongs to be JPA annotation, therefore, I don't know if there is anything equivalent in orm.xml? I have had a look at the xml schema of orm.xml, and there is not such hibernate element permitted in the schema.

If I can't do the second-level cache config in the orm.xml, is there any way other than in the annotation? The reason that I don't want to do it the annotation is because I have two applications, one use READ_WRITE concurrency strategy and another use READ_ONLY concurrency strategy.

Thanks in advance!!!

Kewei

Was it helpful?

Solution 3

So Therefore, I think the current solution for my problem is to replace all the annotations of each entities with Hibernate mapping files, so that for different deployment (application as well), we could use different Hibernate mapping files.

OTHER TIPS

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

If you don't want to use annotations, then check the documentation of your hibernate second level cache implementation (a.k.a "cache provider", for example, ehcache) how to configure it.

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

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