This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes How do I evict data from the Hibernate first level cache (but not the second level cache)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How do I evict data from the Hibernate first level cache (but not the second level cache)?" Watch "How do I evict data from the Hibernate first level cache (but not the second level cache)?" New topic
Author

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

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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
 
 
subject: How do I evict data from the Hibernate first level cache (but not the second level cache)?
 
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
Why isn't an exception being thrown in my JUnit test?
Query when Using EHCache mechanism
Clearing L2 Cache using hibernate