Hello,
I'm having a weird problem that I think might be cache related but I'm not sure at this point.
I have created a TestCase that does the following:
- Save an object using an outside application (thru Selenium)
- Fetch the object using hibernate and detached objects (session is opened then closed immediately).
- Delete the object using the outside application
- Try to refetch the object using hibernate
At the last step, I would expect to get an ObjectNotFoundException but instead, I fetch the object as if it hadn't been deleted. I tried putting a breakpoint before and checking the database and the object was well deleted.
I therefore thought that this was a caching problem and read on hibernate and cache. It doesn't seem to be a first level cache problem because my fetch opens and closes the session each time (therefore not the same session is used for both fetches). I thought it must then be a second level cache problem but I do not set it anywhere (for any collection or entity) and I even tried using (hibernate.cache.use_second_level_cache=false). No success...
Even more weird is when I use the "show_sql" option, it seems to actually go to the database on the second fetch...
Any clue where hibernate seems to get the instance that is not in the database anymore?
Hibernate version:3.2.2
Code between sessionFactory.openSession() and session.close():
Code:
Session session = currentSession();
ProductPriority toReturn = null;
try {
toReturn = (ProductPriority) session.get(ProductPriority.class, id);
} catch (HibernateException he) {
throw new DAOException(he);
} finally {
// Close the hibernate session
closeSession();
}
Name and version of the database you are using: Mysql 5Test CaseCode:
ProductPriority productPriority = new ProductPriority();
productPriority.setName("Test" + new Date().getTime());
//Save the object from an outside interface
se.open(AUTBrowserLauncher.getInstance().getIndexUrl());
authenticationHelper.login("admin", "admin");
productPriorityAcceptanceHelper.goToProductPriorityListPage();
productPriorityAcceptanceHelper.addProductPriority();
productPriorityAcceptanceHelper.populateMaximalProductPriority(productPriority, "");
String id = productPriorityAcceptanceHelper.saveProductPriority();
productPriority.setId(id);
//Fetch the entity while it is still "persisted"
ProductPriorityBusinessObjectFacade.getInstance().fetchProductPriority(productPriority.getId());
//Delete the object from an outsied interface
productPriorityAcceptanceHelper.deleteProductPriority(productPriority);
authenticationHelper.logout();
//Fetch the object again (should have been deleted)
try {
ProductPriorityBusinessObjectFacade.getInstance().fetchProductPriority(productPriority.getId());
fail("Object should have been deleted and therefore should not have been fetched");
} catch (ProductPriorityNotFoundException e) {
//Ok to catch
}