Tested with the Hibernate 4.3.8. Attached the test program to demo the issue.
Includes 1.optimistic-lock-test.jar 2.Dependencies in folder "optimistic-lock-test_lib" 3.Eclipse project source in folder "OptimisticLockTestProgram"
Steps to execute
1. create table CREATE TABLE `stock` ( `STOCK_ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `STOCK_NAME` varchar(100) DEFAULT NULL, `NAME` varchar(20) DEFAULT NULL, `AGE` varchar(25) NOT NULL DEFAULT '0', PRIMARY KEY (`STOCK_ID`) USING BTREE ) ENGINE=InnoDB;
2. execute java -jar optimistic-lock-test.jar , please have the dependency directory "optimistic-lock-test_lib" in the path as optimistic-lock-test.jar
3. The hbm.xml has optimistic lock turned on at component and disabled at component property. <component name="componentPart" class="com.test.ComponentPart" optimistic-lock="true">
<property name="name" type="string" optimistic-lock="false"> <column name="NAME" /> </property>
<property name="age" type="string" optimistic-lock="false"> <column name="AGE" /> </property>
</component>
3.On update to the record, hibernate generates the following sql Hibernate: update stock set STOCK_NAME=?, NAME=?, AGE=? where STOCK_ID=? and STOCK_NAME=? and NAME=? and AGE=? Note: "and NAME=? and AGE=?" is not expected as optimistic-lock="false" for NAME AND AGE columns
|