Results 1 to 3 of 3

Thread: hibernate cache and saveOrUpdate() question

  1. #1

    Default hibernate cache and saveOrUpdate() question

    Hello -

    I have a need to fetch an object to capture a "before" snapshot and then update the object, persist the change to DB, then capture the "after" snapshot. I was hoping I could fetch the object from the database using getHibernateTemplate().find() method and then when the saveOrUpdate() method was called hibernate would first look in the cache and use that object instead of going back to the database which would result in two fetches.

    For example

    Code:
                // incoming object from client
                DocumentFamily df = (DocumentFamily) aObject;
    
                ArrayList list = new ArrayList(2);
                list.add(DocumentFamily.class);
                list.add(df.getCaseUuid());
    
                AbstractService service = (AbstractService)serviceList.get(0);
    
                // fetch object using getHibernateTemplate().find()
                DocumentFamily df2 = (DocumentFamily) service.fetch(list);
                // write out before snapshot
    
    
                // update incoming document family (df)
                // calls getHibernateTemplate.saveOrUpdate() - using DocumentFamily object from cache
                service.update(df);
    Can anyone comment on whether I can use the cache in this way or if there's a better way to achieve this?

    cheers.

  2. #2

    Default

    As a follow up question. How can I tell if an object is retrievedfrom the cache?

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I'm not 100% sure, but wouldn't Hibernate need to go back to the database to do version checking on the entity?
    Last edited by karldmoore; Aug 29th, 2007 at 11:58 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •