These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cache Invalidation problem.
PostPosted: Mon Apr 09, 2007 12:05 pm 

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43

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():
        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

Name and version of the database you are using: Mysql 5

Test Case
        ProductPriority productPriority = new ProductPriority();
        productPriority.setName("Test" + new Date().getTime());
        //Save the object from an outside interface
        authenticationHelper.login("admin", "admin");
        productPriorityAcceptanceHelper.populateMaximalProductPriority(productPriority, "");
        String id = productPriorityAcceptanceHelper.saveProductPriority();

        //Fetch the entity while it is still "persisted"

        //Delete the object from an outsied interface

        //Fetch the object again (should have been deleted)
        try {
            fail("Object should have been deleted and therefore should not have been fetched");
        } catch (ProductPriorityNotFoundException e) {
            //Ok to catch

 Post subject:
PostPosted: Thu Apr 12, 2007 10:24 am 

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43


Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.