Forums Register Login

How do I evict data from the Hibernate first level cache (but not the second level cache)?

+Pie Number of slices to send: Send
Hi,

I'm using Hibernate 4.1.5.Final, Spring 3.1.1.RELEASE, JUnit 4.8.1 and JPA 2.0. I'm trying to test if my second-level cache is set up properly, but I can't figure out how to hit the second level cache. Does anyone know how I can

1.) Evict an entity from the first level cache or
2.) Create a new session within my entity manager in a single JUnit test?

Here's my DAO that I'm trying to test …



Here's the JUnit test …



I think the assertion is failing because I'm using the same session and so my entity is being cached within the first level cache. I'd like to test hitting the second level cache.

Thanks, - Dave
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1664 times.
Similar Threads
Hibernate: persist an object containing a list with more objects
Hibernate is returning proxy objects even if no matching row is found on the database
Query when Using EHCache mechanism
Clearing L2 Cache using hibernate
Why isn't an exception being thrown in my JUnit test?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:50:14.