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 :-

If any of your other classes access the fields of these persistable classes directly then these other classes should be defined as PersistenceAware.

Persistence-Aware Classes

If a class is not itself persistable but it interacts with fields of persistable classes then it should be marked as Persistence Aware. You do this as follows, with XML

<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
{
    ...
}