Reputation: 7022
I'm running into issues unit testing a Hibernate entity with a READ_ONLY cache setting. I need to create new ones during unit testing.
I get the error: Can't write to a readonly object
I've been trying to find a way to disable this cache setting in unit testing.
I was hoping to interact with the meta model but I don't know which property to set to disable caching for this entity or if it's even possible.
Setting the cache on a session level doesn't work because the object hasn't been created yet.
Any suggestions?
Upvotes: 0
Views: 178
Reputation: 485
Selective caching of entities can be achieved via 'shared-cache-mode' element in persistence.xml
ENABLE_SELECTIVE : Entities are not cached unless you explicitly mark them as cachable. This is the default and recommended value.
DISABLE_SELECTIVE : Entities are cached unless you explicitly mark them as not cacheable.
read more here
Upvotes: 1