-->
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: Select (for version column) not being generated after Update
PostPosted: Wed Aug 24, 2016 12:48 pm 
Newbie

Joined: Wed Aug 24, 2016 12:34 pm
Posts: 1
We are trying to migrate from Oracle 11g to SQL Server 2012. We are using Hibernate 3. In the past, with Oracle RDBMS a timestamp column was used for versioning. In an attempt to migrate to SQL Server 2012 we changed the dialect to SQLServerDialect and added a version column to the hibernate configuration file as follows:
<version name="rowVersion" column="ROW_VERSION" type="byte[]" generated="always"/>

After the changes when the entity is being persisted we are seeing StaleStateException: Unexpected row count: 0 expected 1

Also, we noticed that there are some update statements without the version column in the where clause. And there is no select statement to retrieve the version number.

Note: In most cases hibernate is generating update statements with version column in the where clause and it also generates a select statement to retrieve the version value for the recently updated row.
Also, we have PreUpdateEventListeners implemented and there is no call to the method onPreUpdate() whenever the unexpected behavior is seen.

Any input on this is highly appreciated.

Thanks,


Top
 Profile  
 
 Post subject: Re: Select (for version column) not being generated after Update
PostPosted: Mon Aug 29, 2016 6:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
The StaleStateException should be thrown whenever you try to update a stale record and lose updates, which is the whole point of using optimistic locking.

Related to update statement without the version column, I suspect that you are using bulk updates in which case you can use the VERSIONED keyword.

The reason why Hibernate tries to select the version property with a separate query is because you used: generated="always". The use of "always" tells Hibernate that the database changes the version property on every insert and update. Usually, Hibernate manages this property so I don't see why do you have the generated="always" attribute at all. Try removing it and rely on Hibernate for managing the version column.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.