Monday, April 14, 2008

Wiring up bi-directional relationship can cause OptimisticLocking exceptions

Shafiek encountered problem whereby there was a bidirectional one-many relationship between LocationType and Location. When he created a location he added the location to the LocationType to "wire-up" the relationship. This adding of location to the locationType's collection caused version number of LocationType to change which then would cause OptimisticLocking exception.

In Hibernate 3.3 there is an enhancement to allow you to specify whether a property triggers an optimistic lock. But since the jboss we are using does not use this hibernate, as a work around we will just not wire up the relationship in the code that adds the location.

http://opensource.atlassian.com/projects/hibernate/browse/ANN-26

No comments: