Annotation Type Subclass


@Retention(RUNTIME) @Target(TYPE) public @interface Subclass

Indicates that a class is part of a polymorphic persistence hierarchy. Subclasses of an @Entity should be flagged with this annotation.

This is used for Objectify's implementation of polymorphism. Place this on any class in an inheritance hierarchy that should be queryable except the root. For example, in the hierarchy Animal->Mammal->Cat, annotations should be:

  • @Entity Animal
  • @Subclass(index=true) Mammal
  • @Subclass(index=true) Cat

The @Entity annotation must be present on the class that identifies the root of the hierarchy. This class will define the kind of the entire hierarchy. The @Entity annotation must NOT be present on any subclasses.

Actual Java subclasses are not required to have @Subclass, but only Java classes which have @Subclass can be persisted and queried for. Note that subclass discriminators are not indexed by default, so if you want to query for specific types of subclasses, use @Subclass(index=true).

Author:
Jeff Schnitzer
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Additional discriminators which, when encountered, will be interpreted as indicating this subclass.
    boolean
    If true, the discriminator will be indexed, and a query for the specific subclass will return results.
    Optionally define the discriminator value for the subclass; default is Class.getSimpleName()
  • Element Details

    • name

      String name
      Optionally define the discriminator value for the subclass; default is Class.getSimpleName()
      Default:
      ""
    • index

      boolean index

      If true, the discriminator will be indexed, and a query for the specific subclass will return results. However, superclasses and further subclasses may be have different index states.

      This is NOT the same as putting @Index on a class; that sets the default index state of the fields of that class. This attribute only controls indexing of the discriminator.

      Default:
      false
    • alsoLoad

      String[] alsoLoad
      Additional discriminators which, when encountered, will be interpreted as indicating this subclass. Facilitates schema changes in a way analagous to @AlsoLoad.
      Default:
      {}