-->
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.  [ 3 posts ] 
Author Message
 Post subject: Upgrade 3.2.0 to 3.5.6: delete detached object issue
PostPosted: Wed Dec 19, 2012 7:01 am 
Newbie

Joined: Wed Dec 19, 2012 6:34 am
Posts: 3
Hey,

I know we're a bit running behind, but we want to upgrade Hibernate from 3.2.0.cr1 to 3.5.6. We already encountered some small issues, but this one is rather important:

Apparently, the default behavior for deleting an object has been altered. We currently use following scenario in a bunch of our front-end applications:

- session1 loads the object
- display the object on screen
- user presses the delete-button
- session2 performs the actual delete

You see that we detach the object & then delete it. This still works OK in normal situations, but we notice that Hibernate now first tries to select the object before deleting it. This not only performs a useless query, but we get different results if the object was actually not found:

- 3.2.0.cr1: we get a StaleStateException (org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1)
- 3.5.6: the delete simply does nothing, as he didn't found the object in the select, it simply returns

Although it may not be the best way of doing it, several of our applications rely on the fact that this would throw an exception. Is there a config/workaround for this issue?

We're still using a HibernateTemplate, so in the worst case, I could write something around the delete-function to alter the behavior if the session doesn't contain the object yet.. But this is far from ideal.

Thanks in advance,

Sven


Top
 Profile  
 
 Post subject: Re: Upgrade 3.2.0 to 3.5.6: delete detached object issue
PostPosted: Thu Jan 03, 2013 6:43 am 
Newbie

Joined: Wed Dec 19, 2012 6:34 am
Posts: 3
Hi again,


First of all, happy holidays to everyone.. :)

Hasn't anyone experienced the same issues when upgrading Hibernate in a working environment? How did you guys tackle this issue?

*edit*: some other discussion on +- this issue: http://stackoverflow.com/questions/13210638/hibernate-delete-query
-> I understand why Hibernate does that, it's quite logic. However, it is not backwards compatible as it doesn't throw the exception, so for our production environment, this is currently a stopper.


Thanks,

Sven


Top
 Profile  
 
 Post subject: Re: Upgrade 3.2.0 to 3.5.6: delete detached object issue
PostPosted: Fri Jan 04, 2013 2:55 am 
Newbie

Joined: Wed Dec 19, 2012 6:34 am
Posts: 3
Hey again,

What do you guys think of following work-around? Is it safe enough to implement?

I noticed the extra select-query is triggered in the DefaultDeleteEventListener.onDelete(DeleteEvent event, Set transientEntities):

Code:
      if ( entityEntry == null ) {
         log.trace( "entity was not persistent in delete processing" );

         persister = source.getEntityPersister( event.getEntityName(), entity );

         if ( ForeignKeys.isTransient( persister.getEntityName(), entity, null, source ) ) {
            deleteTransientEntity( source, entity, event.isCascadeDeleteEnabled(), persister, transientEntities );
            // EARLY EXIT!!!
            return;
         }
         else {
            ...
         }


So I made a CustomDeleteEventListener which extends the DefaultDeleteEventListener & overrides following method:

Code:

   /* (non-Javadoc)
    * @see org.hibernate.event.def.DefaultDeleteEventListener#deleteTransientEntity(org.hibernate.event.EventSource, java.lang.Object, boolean, org.hibernate.persister.entity.EntityPersister, java.util.Set)
    */
   @Override
   protected void deleteTransientEntity(EventSource session, Object entity,
         boolean cascadeDeleteEnabled, EntityPersister persister,
         Set transientEntities) {
      /* perform the normal deleteTransientEntity-method */
      super.deleteTransientEntity(session, entity, cascadeDeleteEnabled, persister,
            transientEntities);
      /*
       * Backwards compability: in previous Hibernate-versions, trying to
       * delete a transient entity also triggered a StaleStateException.
       * In newer versions, this isn't the case anymore. As a work-around,
       * we'll throw the StaleStateException ourselves.
       */
      if (transientEntities != null && transientEntities.size() > 0) {
         throw new StaleStateException(
               "Unexpected row count: 0 expected: 1"
         );
      }
   }


Thanks,

Sven


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.