JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer
O/R Mapping
Relationships
JDO Versioning

JDO2 allows objects of classes to be versioned. The version is typically used as a way of detecting if the object has been updated by another thread or PersistenceManager since retrieval using the current PersistenceManager - for use by Optimistic Transactions. JDO2s mechanism for versioning of objects in RDBMS datastores is via a surrogate column in the table of the class.

With JDO2 you can specify the details of this surrogate column and additionally the strategy for populating the column. For example

<package name="mydomain">
    <class name="User" table="USER">
        <version strategy="version-number" column="VERSION"/>
        <field name="id" primary-key="true">
            <column name="USER_ID"/>
        </field>
        <field name="login">
            <column name="LOGIN" length="20" jdbc-type="VARCHAR"/>
        </field>
    </class>
</package>

The specification above will create a table with an additional column called "VERSION" that will store the version of the object. The strategy has the following possible values

  • none stores a number like the version-number but will not perform any optimistic checks.
  • version-number stores a number (starting at 1) representing the version of the object.
  • date-time stores a Timestamp representing the time at which the object was last updated. Note that not all RDBMS store milliseconds in a Timestamp!
  • state-image stores a Long value being the hash code of all fields of the object. JPOX doesnt currently support this option