• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dump Hibernate caches

 
Joseph Maddison
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been hinted at by a Hibernate guru/coworker who is more than willing to leave it as an exercise for someone else, that it is possible to somehow code a simple JSP that tells the Hibernate persistence layer to dump all cached rows and/or refresh them from the database. Any ideas on how this would be done?

This comes up because I am using JDBC SQL queries to set/reset data for automated (JUnit) testing. My EJB's are not always picking up the revised data and I suspect that it is due to caching.

At worst, I could switch to using the Hibernate backed entity classes to set up the data for the test, but I was hoping to be able to keep the code simple enough that it could be used to test behavior on multiple, similar tables. Perhaps using reflection with the entity classes could make this more reusable, but I'm not sure that I want to get that deep into it, just for testing. Anyway, I just thought I would ask.

Thanks,
jdmaddison
Minneapolis, MN
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This comes up because I am using JDBC SQL queries to set/reset data for automated (JUnit) testing. My EJB's are not always picking up the revised data and I suspect that it is due to caching.

I'd bet its more likely due to confusion with transactions.

Hibernate has two caching layers. Which one are you talking about?
 
Joseph Maddison
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I'd bet its more likely due to confusion with transactions.

That's possible. I did some more testing and it appears that the SQL update statement is not getting to the database for whatever reason. I've worked around that now.

> Hibernate has two caching layers. Which one are you talking about?

Both the 1st and 2nd level caches, if possible, though the session level one won't really have much in it, if it's specific to this JSP that just dumps the caches.

Thanks,
jdmaddison
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic