JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer
Persistence
Object Identity
Persistent Fields or Properties

There are two distinct modes of persistence definition. The most common uses fields, whereas an alternative (new in JPOX 1.2) uses properties.

Persistent Fields

The most common form of persistence is where you have a field in a class and want to persist it to the datastore. JPOX has catered for this since its initiation. With this mode of operation JPOX will persist the values stored in the fields into the datastore, and will set the values of the fields when extracting it from the datastore.

Requirement : you have a field in the class. This can be public, protected, private or package access, but cannot be static or final.

An example of how to define the persistence of a field is shown below

JDO:
@PersistenceCapable
public class MyClass
{
    @Persistent
    Date birthday;
}

JPA:
@Entity
public class MyClass
{
    @Basic
    Date birthday;
}

So, using annotations, we have marked this class as persistent, and the field also as persistent. Using XML MetaData we would have done

JDO:
<class name="MyClass">
    <field name="birthday" persistence-modifier="persistent"/>
</class>

JPA:
<entity name="mydomain.MyClass">
    <attributes>
        <basic name="birthday"/>
    </attributes>
</entity>


Persistent Properties

A second mode of operation is where you have Java Bean-style getter/setter for a property. In this situation you want to persist the output from getXXX to the datastore, and use the setXXX to load up the value into the object when extracting it from the datastore.

Requirement : you have a property in the class with Java Bean getter/setter methods. These methods can be public, protected, private or package access, but cannot be static. The class must have BOTH getter AND setter methods.

An example of how to define the persistence of a property is shown below

JDO:
@PersistenceCapable
public class MyClass
{
    @Persistent
    Date getBirthday()
    {
        ...
    }

    void setBirthday(Date date)
    {
        ...
    }
}

JPA:
@Entity
public class MyClass
{
    @Basic
    Date getBirthday()
    {
        ...
    }

    void setBirthday(Date date)
    {
        ...
    }
}

So, using annotations, we have marked this class as persistent, and the getter is marked as persistent. Using XML MetaData we would have done

JDO:
<class name="MyClass">
    <property name="birthday" persistence-modifier="persistent"/>
</class>

JPA:
<entity name="mydomain.MyClass">
    <attributes>
        <basic name="birthday"/>
    </attributes>
</entity>
Please note that the BCEL enhancer supports persistent properties from 1.2.0-beta-2, and the ASM enhancer supports persistent properties after 1.2.0-beta-4.