This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman 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 Elasticsearch in Action this week in the Big Data 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I evict data from the Hibernate first level cache (but not the second level cache)?