JDO requires that implementations support the persistence of java.lang.Object as first class
objects (FCO's). DataNucleus provides this capability and also provides that java.lang.Object
can be stored as serialised. It follows the same general process as for
Interfaces since both interfaces and java.lang.Object are
to some persistable object.
JDO doesn't define how an object FCO is persisted in the datastore. Obviously there can be
many "implementations" and so no obvious solution. DataNucleus allows the following
The user controls which one of these is to be used by specifying the
on the field containing the interface.
The default is "per-implementation"
Let's suppose you have a field in a class and you have a selection of possible persistable class that
could be stored there, so you decide to make the field a
So let's take an example. We have the following class
public class ParkingSpace
So we have a space in a car park, and in that space we have an occupier of the space. We have some
legacy data and so can't make the type of this "occupier" an interface type, so we just use
. Now we know that we can only have particular types of objects stored there
(since there are only a few types of vehicle that can enter the car park).
So we define our MetaData like this
<field name="occupier" persistence-modifier="persistent"
or using annotations
This will result in the following database schema.
So DataNucleus adds foreign keys from the ParkingSpace table to all of the possible implementation tables
In conclusion, when using "per-implementation" mapping for any java.lang.Object field in a
class to be persisted (as non-serialised), you
define the possible
"implementation" classes that can be stored there.
If we use
of "identity" then we get a different datastore schema.
<field name="occupier" persistence-modifier="persistent">
<extension vendor-name="datanucleus" key="mapping-strategy" value="identity"/>
and the datastore schema becomes
and the column "OCCUPIER" will contain strings such as
allowing retrieval of the related implementation
By default a field of type
is stored as an instance of the underlying
PersistenceCapable in the table of that object. If either your Object field represents
non-PersistenceCapable objects or you simply wish to serialise the Object into the same table as
the owning object, you need to specify the "serialized" attribute, like this
<field name="myObject" serialized="true"/>
Similarly, where you have a collection of Objects using a join table, the objects are, by default,
stored in the table of the PersistenceCapable instance. If instead you want them to occupy a single
BLOB column of the join table, you should specify the "embedded-element" attribute of
<collection> like this
<collection element-type="java.lang.Object" serialized-element="true"/>
Please refer to the serialised fields guide for more details
of storing objects in this way.