-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate versioning problem
PostPosted: Wed Feb 09, 2011 10:49 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
In our application we have a Hibernate interceptor which may revert all changes made to an entity in the onFlushDirty() method, based on various conditions. After doing so, our onFlushDirty() implementation returns true indicating that the currentState array has changed.

It works as expected in most cases but we experience the following if all property values are reverted:
- the entity is not updated in the database - as expected
- the version number of the entity is still incremented - this seems strange because the database and the entity will not be in sync after flush

I investigated the problem and found the following code in DefaultFlushEntityEventListener.isVersionIncrementRequired():

Code:
   private boolean isVersionIncrementRequired(
         FlushEntityEvent event,
         EntityEntry entry,
         EntityPersister persister,
         int[] dirtyProperties
   ) {
      final boolean isVersionIncrementRequired = entry.getStatus()!=Status.DELETED && (
            dirtyProperties==null ||
            Versioning.isVersionIncrementRequired(
                  dirtyProperties,
                  event.hasDirtyCollection(),
                  persister.getPropertyVersionability()
               )
         );
      return isVersionIncrementRequired;
   }


In our case dirtyProperties is null (because all dirty properties were reverted by the interceptor), so isVersionIncrementRequired() will return true.
It means that the version is incremented even if no properties were changed and no database update is performed when flushing.

What do you think, is this the expected behaviour?

We use 3.6.0-Final.

Thanks for your help in advance!
Norbi


Top
 Profile  
 
 Post subject: Re: Hibernate versioning problem
PostPosted: Thu Feb 10, 2011 3:01 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
I think this is a bug, so I filed an issue: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5911


Top
 Profile  
 
 Post subject: Re: Hibernate versioning problem
PostPosted: Thu Feb 10, 2011 9:05 am 
Newbie

Joined: Wed Jan 26, 2011 12:32 pm
Posts: 12
With my limited knowledge, I can say this is not a bug
In case of ROLLBACK its program responsibility to clear the version column . Hibernate only take care of database


Top
 Profile  
 
 Post subject: Re: Hibernate versioning problem
PostPosted: Thu Feb 10, 2011 9:22 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
It's not a database rollback.
I modify the state of the entity in a Hibernate-supported way, using the Interceptor.onFlushDirty() method. It works in most cases, it fails only when all properties were reverted to their original values.

Thanks for your reply!
Regards:
Norbi


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