-->
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: BUG? Can't get access to the original record anymore
PostPosted: Fri May 12, 2006 12:14 pm 
Regular
Regular

Joined: Tue Jun 08, 2004 8:24 am
Posts: 57
On my existing application, I have a logging system that tracks changes to data objects and logs them.

When my business layer's update method is called, I load the original contents from the database and make a comparison like so:

Code:
   public void update(Group group)
   {
      Group original = groupDAO.get(group.getId());
      log.info(SECTION_NAME, "Update", "Changes:\n"
            + BeanTool.diff(original, group, "\n", ignoreProperties)
            + "\n------------------------------\nOriginal:\n"
            + BeanTool.makeString(original, "\n", ignoreProperties));
      // We have to do this because the object just loaded from the DB is the
      // one attached to the hibernate session.
      BeanTool.copyProperties(group, original);

      groupDAO.update(original);
   }


Where groupDAO operates like so:

Code:
   public Group get(int id)
   {
      return (Group)getHibernateTemplate().get(Group.class,
            new Integer(id));
   }

   public void update(Group group)
   {
      getHibernateTemplate().update(group);
   }


When I upgraded Hibernate from 3.0.5 to 3.1.3, this stopped working.
Now, if I try to load the database copy, Hibernate simply gives me back the one I've already changed, even though I haven't actually written it to the database.

This gets even worse in other areas, where a user makes some changes (which I write to the object) but then clicks cancel on one of the pages.
Even though I haven't saved it to the database, hibernate keeps giving back the modified object on subsequent loads instead of what's actually stored in the database.

Is this a bug?
A feature?
If so, how do I turn it off?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 5:27 pm 
Newbie

Joined: Fri Nov 04, 2005 11:37 am
Posts: 6
I guess detaching your group object (session.evict(group)) before modifing may solve your problem

-P


Top
 Profile  
 
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.