Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!