Making ehcache read-write for test code and read-only for production code

Posted by Rick on Stack Overflow See other posts from Stack Overflow or by Rick
Published on 2010-05-12T18:35:10Z Indexed on 2010/05/15 0:24 UTC
Read the original article Hit count: 718

Filed under:
|
|

I would like to annotate many of my Hibernate entities that contain reference data and/or configuration data with

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)

However, my JUnit tests are setting up and tearing down some of this reference/configuration data using the Hibernate entities. Is there a recommended way of having entities be read-write during test setup and teardown but read-only for production code?

Two of my immediate thoughts for non-ideal workarounds are:

  • Using NONSTRICT_READ_WRITE, but I am not sure what the hidden downsides are.
  • Creating subclassed entities in my test code to override the read-only cache annotation.

Any recommendations on the cleanest way to handle this?

(Note: Project uses maven.)

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about ehcache