While JPA defines support for application identity only
DataNucleus also provides support for
you are leaving the assignment of id's to DataNucleus and your class will
have a field
for this identity - it will be added to the datastore representation by DataNucleus.
It is, to all extents and purposes a
that will have its own column in the
datastore. To specify that a class is to use
with JDO, you define the
following annotations on your class
public class MyClass
Please note that since the JPA XML metadata is poorly designed it is not possible to specify
datastore identity using XML, you have to use the annotations.
When you have an inheritance hierarchy, you should specify the identity type in the
class for the inheritance tree. This is then used for all persistent classes
in the tree.
you are handing the process of identity generation to the
JDO implementation. This does not mean that you haven't got any control over how it does this.
JDO 2 defines many ways of generating these identities and DataNucleus supports all of these and
provides some more of its own besides.
Defining which one to use is a simple matter of adding a MetaData element to your classes
definition, like this
public class MyClass
See also :-
, the class has no associated field so you can't just
access a field of the class to see its identity - if you need a field to be able to access the
identity then you should be usingapplication identity.
There are, however, ways to get the identity for the datastore identity case, if you have the
Object id = JDOHelper.getObjectId(obj);
You should be aware however that the "identity" is in a complicated form, and is not available as
a simple integer value for example. Again, if you want an identity of that form then you should use
DataNucleus provides a public class that represents
this identity. If you call
for a class using
datastore identity you will be passed an object which, in the case of DataNucleus will be of
. If you were to call "toString()" on this object
you would get something like
This is made up of :-
1 = identity number of this object
DataNucleus allows you the luxury of being able to
provide your own datastore identity class
so you can have whatever formatting you want for identities.
You can also access the object from the object class name and the toString() form of the
datastore identity (e.g "1[OID]mydomain.MyClass") like this
Object obj = em.find(MyClass.class, mykey);