Hi,

I think I found a minor bug in the optimistic locking (OL)
code/documentation

If you initialise an int field to use OL (locking="true") then updates
will fail if the field is null, either silently or with a
LockNotGrantedException.

public class MyClass {
        private Integer id;
        private int ojbVersion;
}

<class-descriptor class="MyClass" table="MyClassTable"> 
        <field-descriptor name="id" column="id" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
        <field-descriptor name="ojbVersion" column="ojb_version"
jdbc-type="INTEGER" locking="true"/>
</class-descriptor>
 
If a new object is created and persisted, the ojb_version field is set
to 1
If another app inserts a record and the ojb_version field is null, when
it is persisted then this SQL gets executed.
  UPDATE MyClassTable SET ojb_version='1', ... WHERE id='723' AND
ojb_version='0'

Sometimes this throws an exception, othertimes it seems to silently
fail.

Obviously it's the old int/Integer thing :)
But in
http://db.apache.org/ojb/faq.html#How%20to%20set%20up%20Optimistic%20Loc
king it has:
 private int versionMaintainedByOjb

Should the docs be changed to 'private Integer versionMaintainedByOjb'?
If so, will it have issues 'incrementing' a null value? Or should in the
docs it state 'make this table field default to a non-null value (eg.
0)'? Or should the code be doing 'UPDATE MyClassTable SET
ojb_version='1', ... WHERE id='723' AND (ojb_version='0' OR ojb_version
is NULL)'?

Thanks,

Rob :)


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to