Search code examples
javaxmlhibernateormsecond-level-cache

Hibernate second-level cache in orm.xml?


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


Solution

  • 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.