Announcement Announcement Module
Collapse
No announcement yet.
hibernate cache and saveOrUpdate() question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    As a follow up question. How can I tell if an object is retrievedfrom the cache?

    Comment


    • #3
      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, 12:58 PM.

      Comment

      Working...
      X