JPA Versioning

JPA1 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 EntityManager since retrieval using the current EntityManager - for use by Optimistic Transactions. JPA1s mechanism for versioning of objects in RDBMS datastores is to mark a field of the class to store the version. The field must be Integer/Long based.

With JPA1 you can specify the details of this version field as follows.

<entity name="mydomain.User">
        <id name="id"/>
        <version name="version"/>

or alternatively using annotations

public class User
    long id;

    int version;


The specification above will use the "version" field for storing the version of the object. DataNucleus will use a "version-number" strategy for populating the value (see JDO Versioning for details of the strategies that JDO allows).