@Discriminator (jdo)

The @javax.jdo.annotation.Discriminator is used by JDO/DataNucleus to specify how to discriminate between subclasses of an inheritance hierarchy.

It is valid to add a @Discriminator for any class, even those not part of an explicitly mapped inheritance hierarchy. Apache Isis also checks for this annotation, and if present will use the @Discriminator#value() as the object type, a unique alias for the object’s class name.

Isis parses the @Discriminator annotation from the Java source code; it does not query the JDO metamodel. This means that it the @Discriminator annotation must be used rather than the equivalent <discriminator> XML metadata.

Moreover, while JDO/DataNucleus will recognize annotations on either the field or the getter method, Apache Isis (currently) only inspects the getter method. Therefore ensure that the annotation is placed there.

This value is used internally to generate a string representation of an objects identity (the Oid). This can appear in several contexts, including:

Examples

For example:

@javax.jdo.annotations.Discriminator(value="custmgmt.Customer")
public class Customer {
    ...
}

has an object type of custmgmt.Customer.

Precedence

The rules of precedence for determining a domain object’s object type are:

  1. @Discriminator

  2. @DomainObject#objectType

  3. @PersistenceCapable, if at least the schema attribute is defined.

    If both schema and table are defined, then the value is “schema.table”. If only schema is defined, then the value is “schema.className”.

  4. Fully qualified class name of the entity.

This might be obvious, but to make explicit: we recommend that you always specify an object type for your domain objects.

Otherwise, if you refactor your code (change class name or move package), then any externally held references to the OID of the object will break. At best this will require a data migration in the database; at worst it could cause external clients accessing data through the Restful Objects viewer to break.

If the object type is not unique across all domain classes then the framework will fail-fast and fail to boot. An error message will be printed in the log to help you determine which classes have duplicate object tyoes.