Hi,
I am trying to implement optimistic locking using hibernate and it is working fine. But I observed the version number is getting updated multiple times(and it is always starting with 6). Couple of months back, I implemented this in my prototype-and it worked fine.
Am I missing something here?. below is the xml mapping file and log (Orders table is updated multiple times)
<class
name="com.xxx.OrderDTO"
table="orders"
>
<id
name="orderNumber"
type="java.lang.Integer"
column="OrderNumber"
>
<generator class="increment"/>
</id>
<version name="version" column="VERSIONNUMBER"/>
<property-----
/>
<set
name="orderhistories"
inverse="true"
lazy = "false"
order-by="modifiedDate asc"
>
<key>
<column name="OrderNumber"/>
</key>
<one-to-many
class="com.xxx.OrderHistoryDTO"
/>
</set>
<bag
name="tasks"
inverse = "true"
>
<key>
<column name="OrderNumber"/>
</key>
<one-to-many
class="com.xxx.TaskDTO"
/>
</bag>
<joined-subclass
name="com.xxx.OrderBrochureDTO"
table="orderbrochure">
<key column="orderNumber"/>
<property
name="planNum"
type="java.lang.String"
column="PlanNum"
/>
<property
/>
</joined-subclass>
<joined-subclass
name="com.xxx.SalesMaterialOrderDTO"
table="OrderSalesMaterial"
entity-name="SalesMaterialOrderDTO"
>
<key column="orderNumber"/>
<property
/>
<joined-subclass
name="com.xxx.PermitOrderDTO"
table="OrderPermit"
>
<key column="orderNumber"/>
<property
/>
</joined-subclass>
</class>
</hibernate-mapping>
] Hibernate: insert into orders (VERSIONNUMBER, parentOrderNumber, specialInstructions, OrderTypeCod
e, DeltekProjectNumber, RequestedByID, OrderDate, EstCompletionDate, RevCompletionDate, DeltekTaskNu
mber, CostCenterPrefix, AssignedTo, OrderNumber) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
18:35:07,984 INFO [STDOUT] Hibernate: insert into OrderSalesMaterial (estimatedPrintDate, isBrochur
eInsertRequired, isSalesOfficeDisplayRequired, isBaseHousePlanRequired, isApprovedByManager, isOptio
nsPlanRequired, baseHouseGarageConfigCode, handOfHouseCode, quantity, planNum, orderNumber) values (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
18:35:08,014 INFO [STDOUT] address DTO ---get ship to name willow grove
18:35:08,024 INFO [STDOUT] Hibernate: insert into OrderShippingAddress (ShipToName, StreetAddress,
City, StateCode, ZipCode, TelephoneNumber, FaxNumber, OrderNumber) values (?, ?, ?, ?, ?, ?, ?, ?)
18:35:08,054 INFO [STDOUT] Hibernate: update orders set VERSIONNUMBER=?, parentOrderNumber=?, speci
alInstructions=?, OrderTypeCode=?, DeltekProjectNumber=?, RequestedByID=?, OrderDate=?, EstCompletio
nDate=?, RevCompletionDate=?, DeltekTaskNumber=?, CostCenterPrefix=?, AssignedTo=? where OrderNumber
=? and VERSIONNUMBER=?
18:35:08,084 INFO [STDOUT] Hibernate: insert into OrderSalesMaterialArtWork (isRequireWallRendering
, artWorkId, elevationCode, planNum, OrderNumber, positionOfElevation) values (?, ?, ?, ?, ?, ?)
18:35:08,114 INFO [STDOUT] Hibernate: update orders set VERSIONNUMBER=?, parentOrderNumber=?, speci
alInstructions=?, OrderTypeCode=?, DeltekProjectNumber=?, RequestedByID=?, OrderDate=?, EstCompletio
nDate=?, RevCompletionDate=?, DeltekTaskNumber=?, CostCenterPrefix=?, AssignedTo=? where OrderNumber
=? and VERSIONNUMBER=?
18:35:08,144 INFO [STDOUT] Hibernate: insert into OrderSalesMaterialArtWork (isRequireWallRendering
, artWorkId, elevationCode, planNum, OrderNumber, positionOfElevation) values (?, ?, ?, ?, ?, ?)
18:35:08,164 INFO [STDOUT] Hibernate: update orders set VERSIONNUMBER=?, parentOrderNumber=?, speci
alInstructions=?, OrderTypeCode=?, DeltekProjectNumber=?, RequestedByID=?, OrderDate=?, EstCompletio
nDate=?, RevCompletionDate=?, DeltekTaskNumber=?, CostCenterPrefix=?, AssignedTo=? where OrderNumber
=? and VERSIONNUMBER=?
18:35:08,194 INFO [STDOUT] Hibernate: insert into OrderSalesMaterialOption (SequenceNumber, OrderNu
mber, OptionNumber, PlanNum, OptionMasterInstructionalCode) values (?, ?, ?, ?, ?)
18:35:08,214 INFO [STDOUT] Hibernate: update orders set VERSIONNUMBER=?, parentOrderNumber=?, speci
alInstructions=?, OrderTypeCode=?, DeltekProjectNumber=?, RequestedByID=?, OrderDate=?, EstCompletio
nDate=?, RevCompletionDate=?, DeltekTaskNumber=?, CostCenterPrefix=?, AssignedTo=? where OrderNumber
=? and VERSIONNUMBER=?
18:35:08,234 INFO [STDOUT] Hibernate: insert into orderhistory (Comment, OrderStatusCode, OrderType
Code, ModifiedByID, OrderNumber, ModifiedDate) values (?, ?, ?, ?, ?, ?)
18:35:08,264 INFO [STDOUT] Hibernate: update orders set VERSIONNUMBER=?, parentOrderNumber=?, speci
alInstructions=?, OrderTypeCode=?, DeltekProjectNumber=?, RequestedByID=?, OrderDate=?, EstCompletio
nDate=?, RevCompletionDate=?, DeltekTaskNumber=?, CostCenterPrefix=?, AssignedTo=? where OrderNumber
=? and VERSIONNUMBER=?
18:35:08,294 INFO [STDOUT] Hibernate: update orders set VERSIONNUMBER=?, parentOrderNumber=?, speci
alInstructions=?, OrderTypeCode=?, DeltekProjectNumber=?, RequestedByID=?, OrderDate=?, EstCompletio
nDate=?, RevCompletionDate=?, DeltekTaskNumber=?, CostCenterPrefix=?, AssignedTo=? where OrderNumber
=? and VERSIONNUMBER=?
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: