JDO : Class Mapping

The first thing to decide when implementing your persistence layer is which classes are to be persisted. Let's take a sample class ( Hotel ) as an example We can define a class as persistable using either annotations in the class, or XML metadata.

To achieve the above aim with XML metadata, we do this

<class name="Hotel">
    ...
</class>

Alternatively, using JDO Annotations, like this

@PersistenceCapable
public class Hotel
{
    ...
}

See also :-

Persistence-Aware Classes

With JDO persistence all classes that are persisted have to be identified in XML or annotations as shown above. In addition, if any of your other classes access the fields of these persistable classes directly then these other classes should be defined as PersistenceAware . You do this as follows

<class name="MyClass" persistence-modifier="persistence-aware">
    ...
</class>

or with annotations

@PersistenceAware
public class MyClass
{
    ...
}

See also :-



Read-Only

You can, if you wish, make a class read-only . This is a DataNucleus extension and you set it as follows

<class name="MyClass">
    <extension vendor-name="datanucleus" key="read-only" value="true"/>

or with annotations

@PersistenceCapable
@Extension(vendorName="datanucleus", key="read-only", value="true")
public class MyClass
{
    ...
}