JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer
Persistence
Object Identity
JPA Annotations

One of the things that JDK 1.5 provides that can be of some use to JPOX is annotations. JPOX supports both JPA1 and JDO2 annotations. In this section we will document some of the more important JPA1 annotations. When selecting to use annotations please bear in mind the following :-

  • You must be using JDK 1.5 or above. Annotations are not available in earlier JDKs
  • You must have the JPOX Java5 plugin available in your CLASSPATH.
  • Annotations should really only be used for attributes of persistence that you won't be changing at deployment. Things such as table and column names shouldn't really be specified using annotations although it is permitted. Instead it would be better to put such information in an ORM file.
  • Annotations can be added in two places - for the class as a whole, or for a field in particular.
  • You can annotate fields or getters with field-level information. It doesn't matter which.
  • Annotations are prefixed by the @ symbol and can take properties (in brackets after the name, comma-separated)
  • JPA doesn't provide for some key JDO concepts and JPOX provides its own annotations for these cases.
  • You have to import "javax.persistence.XXX" where XXX is the annotation name of a JPA annotation
  • You have to import "org.jpox.annotations.jpa.XXX" where XXX is the annotation name of a JPOX value-added annotation

Annotations supported by JPOX are shown below. Not all have their documentation written yet. The annotations/attributes coloured in pink are ORM and really should be placed in MetaData rather than directly in the class using annotations. The annotations coloured in blue are JPOX extensions and should be used only where you dont mind losing implementation-independence.

AnnotationClass/FieldDescription
@EntityClassSpecifies that the class is persistent
@MappedSuperclassClassSpecifies that this class contains persistent information to be mapped
@PersistenceAwareClassSpecifies that the class is not persistent but needs to be able to access fields of persistent classes
@EmbeddableClassSpecifies that the class is persistent embedded in another persistent class
@InheritanceClassSpecifies the inheritance model for persisting this class
@IdClassClassDefines the primary key class for this class
@DatastoreIdentityClassDefines a class as using datastore-identity (JPOX extension).
@EntityListenersClassSpecifies class(es) that are listeners for events from instances of this class
@NamedQueriesClassDefines a series of named (JPQL) queries for use in the current persistence unit
@NamedQueryClassDefines a named (JPQL) query for use in the current persistence unit
@NamedNativeQueryClassDefines a named (SQL) query for use in the current persistence unit
@NamedNativeQueriesClassDefines a series of named (SQL) queries for use in the current persistence unit
@SqlResultSetMappingClassDefines a result mapping for an SQL query for use in the current persistence unit
@SqlResultSetMappingsClassDefines a series of mappings for SQL queries for use in the current persistence unit
@TableClassDefines the table where this class will be stored
@SecondaryTableClassDefines a secondary table where some fields of this class will be stored
@DiscriminatorColumnClassDefines the column where any discriminator will be stored
@DiscriminatorValueClassDefines the value to be used in the discriminator for objects of this class
@PrimaryKeyJoinColumnsClassDefines the names of the PK columns when this class has a superclass
@PrimaryKeyJoinColumnClassDefines the name of the PK column when this class has a superclass
@AttributeOverrideClassDefines a field in a superclass that will have its column overridden
@AttributeOverridesClassDefines the field(s) of superclasses that will have their columns overridden
@AssociationOverrideClassDefines a N-1/1-1 field in a superclass that will have its column overridden
@AssociationOverridesClassDefines the N-1/1-1 field(s) of superclasses that will have their columns overridden
@SequenceGeneratorClass/Field/MethodDefines a generator of values using sequences in the datastore for use with persistent entities
@TableGeneratorClass/Field/MethodDefines a generator of sequences using a table in the datastore for use with persistent entities
@EmbeddedField/MethodDefines this field as being embedded
@IdField/MethodDefines this field as being (part of) the identity for the class
@EmbeddedIdField/MethodDefines this field as being (part of) the identity for the class, and being embedded into this class
@VersionField/MethodDefines this field as storing the version for the class
@BasicField/MethodDefines this field as being persistent
@TransientField/MethodDefines this field as being transient (not persisted)
@OneToOneField/MethodDefines this field as being a 1-1 relation with another persistent entity
@OneToManyField/MethodDefines this field as being a 1-N relation with other persistent entities
@ManyToManyField/MethodDefines this field as being a M-N relation with other persistent entities
@ManyToOneField/MethodDefines this field as being a N-1 relation with another persistent entity
@GeneratedValueField/MethodDefines that this field has its value generated using a generator
@MapKeyField/MethodDefines that this field is the key to a map
@OrderByField/MethodDefines the field(s) used for ordering the elements in this collection
@PrePersistField/MethodDefines this method as being a callback for pre-persist events
@PostPersistField/MethodDefines this method as being a callback for post-persist events
@PreRemoveField/MethodDefines this method as being a callback for pre-remove events
@PostRemoveField/MethodDefines this method as being a callback for post-remove events
@PreUpdateField/MethodDefines this method as being a callback for pre-update events
@PostUpdateField/MethodDefines this method as being a callback for post-update events
@PostLoadField/MethodDefines this method as being a callback for post-load events
@JoinTableField/MethodDefines this field as being stored using a join table
@LobField/MethodDefines this field as being stored as a large object
@TemporalField/MethodDefines this field as storing temporal data
@EnumeratedField/MethodDefines this field as storing enumerated data
@ColumnField/MethodDefines the column where this field is stored
@JoinColumnField/MethodDefines a column for joining to either a join table or foreign key relation
@JoinColumnsField/MethodDefines the columns for joining to either a join table or foreign key relation (1-1, 1-N, N-1)
@ExtensionsClass/Field/MethodDefines a series of JPOX extensions
@ExtensionClass/Field/MethodDefines a JPOX extension


@Entity

This annotation is used when you want to mark a class as persistent. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the entity (used in JPQL to refer to the class)
@Entity
public class MyClass
{
    ...
}




@MappedSuperclass

This annotation is used when you want to mark a class as persistent but without a table of its own and being the superclass of the class that has a table, meaning that all of its fields are persisted into the table of its subclass. Specified on the class.

@MappedSuperclass
public class MyClass
{
    ...
}




@PersistenceAware

This annotation is used when you want to mark a class as knowing about persistence but not persistent itself. That is, it manipulates the fields of a persistent class directly rather than using accessors. This is a JPOX extension. Specified on the class.

@PersistenceAware
public class MyClass
{
    ...
}




@Embeddable

This annotation is used when you want to mark a class as persistent and only storable embedded in another object. Specified on the class.

@Embeddable
public class MyClass
{
    ...
}




@Inheritance

This annotation is used to define the inheritance persistence for this class. Specified on the class.

AttributeTypeDescriptionDefault
strategyInheritanceTypeInheritance strategySINGLE_TABLE | JOINED | TABLE_PER_CLASS
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class MyClass
{
    ...
}




@Table

This annotation is used to define the table where objects of a class will be stored. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the table
catalogStringName of the catalog
schemaStringName of the schema
uniqueConstraintsUniqueConstraint[]Any unique constraints to apply to the table
@Entity
@Table(name="MYTABLE", schema="PUBLIC")
public class MyClass
{
    ...
}




@SecondaryTable

This annotation is used to define a secondary table where some fields of this class are stored in another table. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the table
catalogStringName of the catalog
schemaStringName of the schema
pkJoinColumnsPrimaryKeyJoinColumns[]Join columns for the PK of the secondary table back to the primary table
uniqueConstraintsUniqueConstraint[]Any unique constraints to apply to the table
@Entity
@Table(name="MYTABLE", schema="PUBLIC")
@SecondaryTable(name="MYOTHERTABLE", schema="PUBLIC", columns={@PrimaryKeyJoinColumn(name="MYCLASS_ID")})
public class MyClass
{
    ...
}




@IdClass

This annotation is used to define a primary-key class for the identity of this class. Specified on the class.

AttributeTypeDescriptionDefault
valueClassIdentity class
@Entity
@IdClass(org.jpox.samples.MyIdentity.class)
public class MyClass
{
    ...
}




@DatastoreIdentity

This JPOX-extension annotation is used to define that the class uses datastore-identity. Specified on the class.

AttributeTypeDescriptionDefault
generationTypeGenerationTypeStrategy to use when generating the values for this field. Has possible values of GenerationType TABLE, SEQUENCE, IDENTITY, AUTO.AUTO | TABLE | SEQUENCE
generatorStringName of the generator to use. See @TableGenerator and @SequenceGenerator
columnStringName of the column for persisting the datastore identity value
@Entity
@DatastoreIdentity(column="MY_ID")
public class MyClass
{
    ...
}




@EntityListeners

This annotation is used to define a class or classes that are listeners for events from instances of this class. Specified on the class.

AttributeTypeDescriptionDefault
valueClass[]Entity listener class(es)
@Entity
@EntityListeners(org.jpox.MyListener.class)
public class MyClass
{
    ...
}




@NamedQueries

This annotation is used to define a series of named (JPQL) queries that can be used in this persistence unit. Specified on the class.

AttributeTypeDescriptionDefault
valueNamedQuery[]The named queries
@Entity
@NamedQueries({@NamedQuery(name="AllPeople", query="SELECT p FROM Person p"),
               @NamedQuery(name="PeopleCalledJones", query="SELECT p FROM Person p WHERE p.surname = 'Jones'")})
public class Person
{
    ...
}




@NamedQuery

This annotation is used to define a named (JPQL) query that can be used in this persistence unit. Specified on the class.

AttributeTypeDescriptionDefault
nameStringSymbolic name for the query. The query will be referred to under this name
queryStringThe JPQL query
@Entity
@NamedQuery(name="AllPeople", query="SELECT p FROM Person p")
public class Person
{
    ...
}




@NamedNativeQueries

This annotation is used to define a series of named native (SQL) queries that can be used in this persistence unit. Specified on the class.

AttributeTypeDescriptionDefault
valueNamedNativeQuery[]The named native queries
@Entity
@NamedNativeQueries({@NamedNativeQuery(name="AllPeople", query="SELECT * FROM PERSON WHERE SURNAME = 'Smith'"),
     @NamedNativeQuery(name="PeopleCalledJones", query="SELECT * FROM PERSON WHERE SURNAME = 'Jones')})
public class Person
{
    ...
}




@NamedNativeQuery

This annotation is used to define a named (SQL) query that can be used in this persistence unit. Specified on the class.

AttributeTypeDescriptionDefault
nameStringSymbolic name for the query. The query will be referred to under this name
queryStringThe SQL query
resultClassClassClass into which the result rows will be placedvoid.class
@Entity
@NamedNativeQuery(name="PeopleCalledSmith", query="SELECT * FROM PERSON WHERE SURNAME = 'Smith'")
public class Person
{
    ...
}




@SqlResultSetMappings

This annotation is used to define a series of result mappings for SQL queries that can be used in this persistence unit. Specified on the class.

AttributeTypeDescriptionDefault
valueSqlResultSetMapping[]The SQL result mappings
@Entity
@SqlResultSetMappings({
    @SqlResultSetMapping(name="PEOPLE_PLUS_AGE",
        entities={@EntityResult(entityClass=Person.class)}, columns={@ColumnResult(name="AGE")}),
    @SqlResultSetMapping(name="FIRST_LAST_NAMES",
        columns={@ColumnResult(name="FIRSTNAME"), @ColumnResult(name="LASTNAME")})
    })
public class Person
{
    ...
}




@SqlResultSetMapping

This annotation is used to define a mapping for the results of an SQL query and can be used in this persistence unit. Specified on the class.

AttributeTypeDescriptionDefault
nameStringSymbolic name for the mapping. The mapping will be referenced under this name
entitiesEntityResult[]Set of entities extracted from the SQL query
columnsColumnResult[]Set of columns extracted directly from the SQL query
@Entity
@SqlResultSetMapping(name="PEOPLE_PLUS_AGE",
    entities={@EntityResult(entityClass=Person.class)}, columns={@ColumnResult(name="AGE")})
public class Person
{
    ...
}




@PrePersist

This annotation is used to define a method that is a callback for pre-persist events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PrePersist
    void registerObject()
    {
        ...
    }
}




@PostPersist

This annotation is used to define a method that is a callback for post-persist events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PostPersist
    void doSomething()
    {
        ...
    }
}




@PreRemove

This annotation is used to define a method that is a callback for pre-remove events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PreRemove
    void registerObject()
    {
        ...
    }
}




@PostRemove

This annotation is used to define a method that is a callback for post-remove events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PostRemove
    void doSomething()
    {
        ...
    }
}




@PreUpdate

This annotation is used to define a method that is a callback for pre-update events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PreUpdate
    void registerObject()
    {
        ...
    }
}




@PostUpdate

This annotation is used to define a method that is a callback for post-update events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PostUpdate
    void doSomething()
    {
        ...
    }
}




@PostLoad

This annotation is used to define a method that is a callback for post-load events. Specified on the method. It has no attributes.

@Entity
public class MyClass
{
    ...

    @PostLoad
    void registerObject()
    {
        ...
    }
}




@SequenceGenerator

This annotation is used to define a generator using sequences in the datastore. It is scoped to the persistence unit. Specified on the class/field/method.

AttributeTypeDescriptionDefault
nameStringName for the generator (required)
sequenceNameStringName of the underlying sequence that will be used
initialValueintInitial value for the sequence (optional)1
allocationSizeintNumber of values to be allocated each time (optional)50
@Entity
@SequenceGenerator(name="MySeq", sequenceName="SEQ_2")
public class MyClass
{
    ...
}




@TableGenerator

This annotation is used to define a generator using a table in the datastore for storing the values. It is scoped to the persistence unit. Specified on the class/field/method.

AttributeTypeDescriptionDefault
nameStringName for the generator (required)
tableStringName of the table to useSEQUENCE_TABLE
catalogStringCatalog of the table to use
schemaStringSchema of the table to use
pkColumnNameStringName of the primary key column for the tableSEQUENCE_NAME
valueColumnNameStringName of the value column for the tableNEXT_VAL
pkColumnValueStringValue to store in the PK column for the row used by this generator{name of the class}
initialValueintInitial value for the table row (optional)0
allocationSizeintNumber of values to be allocated each time (optional)50
@Entity
@TableGenerator(name="MySeq", table="MYAPP_IDENTITIES", pkColumnValue="MyClass")
public class MyClass
{
    ...
}




@DiscriminatorColumn

This annotation is used to define the discriminator column for a class. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the discriminator columnDTYPE
discriminatorTypeDiscriminatorTypeType of the discriminator columnSTRING | CHAR | INTEGER
lengthStringLength of the discriminator column31
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="OBJECT_TYPE", discriminatorType=DiscriminatorType.STRING)
public class MyClass
{
    ...
}




@DiscriminatorValue

This annotation is used to define the value to be stored in the discriminator column for a class (when used). Specified on the class.

AttributeTypeDescriptionDefault
valueStringValue for the discriminator column
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="OBJECT_TYPE", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("MyClass")
public class MyClass
{
    ...
}




@PrimaryKeyJoinColumns

This annotation is used to define the names of the primary key columns when this class has a superclass. Specified on the class.

AttributeTypeDescriptionDefault
valuePrimaryKeyJoinColumn[]Array of column definitions for the primary key
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name="PK_FIELD_1", referredColumnName="BASE_1_ID"),
                        @PrimaryKeyJoinColumn(name="PK_FIELD_2", referredColumnName="BASE_2_ID")})
public class MyClass
{
    ...
}




@PrimaryKeyJoinColumn

This annotation is used to define the name of the primary key column when this class has a superclass. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the column
referencedColumnNameStringName of the associated PK column in the superclass
columnDefinitionStringSome vague JPA attribute that might mean something to each JPA implementation, and its basically SQL. Ignored by JPOX
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@PrimaryKeyJoinColumn(name="PK_FIELD_1")
public class MyClass
{
    ...
}




@AttributeOverride

This annotation is used to define a field of a superclass that has its column overridden. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the field
columnColumnColumn information
@Entity
@AttributeOverride(name="attr", column=@Column(name="NEW_NAME"))
public class MyClass extends MySuperClass
{
    ...
}




@AttributeOverrides

This annotation is used to define fields of a superclass that have their columns overridden. Specified on the class.

AttributeTypeDescriptionDefault
valueAttributeOverride[]The overrides
@Entity
@AttributeOverrides({@AttributeOverride(name="attr1", column=@Column(name="NEW_NAME_1")),
                     @AttributeOverride(name="attr2", column=@Column(name="NEW_NAME_2"))})
public class MyClass extends MySuperClass
{
    ...
}




@AssociationOverride

This annotation is used to define a 1-1/N-1 field of a superclass that has its column overridden. Specified on the class.

AttributeTypeDescriptionDefault
nameStringName of the field
joinColumnJoinColumnColumn information for the FK column
@Entity
@AssociationOverride(name="friend", joinColumn=@JoinColumn(name="FRIEND_ID"))
public class Employee extends Person
{
    ...
}




@AssociationOverrides

This annotation is used to define 1-1/N-1 fields of a superclass that have their columns overridden. Specified on the class.

AttributeTypeDescriptionDefault
valueAssociationOverride[]The overrides
@Entity
@AssociationOverrides({@AssociationOverride(name="friend", joinColumn=@JoinColumn(name="FRIEND_ID")),
                       @AssociationOverride(name="teacher", joinColumn=@JoinColumn(name="TEACHER_ID"))})
public class Employee extends Person
{
    ...
}




@Id

This annotation is used to define a field to use for the identity of the class. Specified on the field/method.

@Entity
public class MyClass
{
    @Id
    long id;
    ...
}




@EmbeddedId

This annotation is used to define a field to use for the identity of the class when embedded. Specified on the field/method.

@Entity
public class MyClass
{
    @EmbeddedId
    MyPrimaryKey pk;
    ...
}




@Version

This annotation is used to define a field as holding the version for the class. Specified on the field/method.

@Entity
public class MyClass
{
    @Id
    long id;

    @Version
    int ver;
    ...
}




@Basic

This annotation is used to define a field of the class as persistent. Specified on the field/method.

AttributeTypeDescriptionDefault
fetchFetchTypeType of fetching for this fieldLAZY | EAGER
optionalbooleanWhether this field having a value is optional (can it have nulls)true | false
@Entity
public class Person
{
    @Id
    long id;

    @Basic(optional=false)
    String forename;
    ...
}




@Transient

This annotation is used to define a field of the class as not persistent. Specified on the field/method.

@Entity
public class Person
{
    @Id
    long id;

    @Transient
    String personalInformation;
    ...
}




@JoinTable

This annotation is used to define that a collection/map is stored using a join table. Specified on the field/method.

AttributeTypeDescriptionDefault
nameStringName of the table
catalogStringName of the catalog
schemaStringName of the schema
joinColumnsJoinColumn[]Columns back to the owning object (with the collection/map)
inverseJoinColumnsJoinColumn[]Columns to the element object (stored in the collection/map)
uniqueConstraintsUniqueConstraint[]Any unique constraints to apply to the table
@Entity
public class Person
{
    @OneToMany
    @JoinTable(name="PEOPLES_FRIENDS")
    Collection friends;
    ...
}




@Lob

This annotation is used to define that a field will be stored using a large object in the datastore. Specified on the field/method.

@Entity
public class Person
{
    @Lob
    byte[] photo;
    ...
}




@Temporal

This annotation is used to define that a field is stored as a temporal type. Specified on the field/method.

AttributeTypeDescriptionDefault
valueTemporalTypeType for storageDATE | TIME | TIMESTAMP
@Entity
public class Person
{
    @Temporal(TemporalType.TIMESTAMP)
    java.util.Date dateOfBirth;
    ...
}




@Enumerated

This annotation is used to define that a field is stored enumerated (not that it wasnt obvious from the type!). Specified on the field/method.

AttributeTypeDescriptionDefault
valueEnumTypeType for storageORDINAL | STRING
enum Gender {MALE, FEMALE};

@Entity
public class Person
{
    @Enumerated
    Gender gender;
    ...
}




@OneToOne

This annotation is used to define that a field represents a 1-1 relation. Specified on the field/method.

AttributeTypeDescriptionDefault
targetEntityClassClass at the other side of the relation
fetchbooleanWhether the field should be fetched immediatelyEAGER | LAZY
optionalbooleanWhether the field can store nulls.true | false
mappedByStringName of the field that owns the relation (specified on the inverse side)
cascadeCascadeType[]Whether persist, update, delete, refresh operations are cascaded
@Entity
public class Person
{
    @OneToOne
    Person bestFriend;
    ...
}




@OneToMany

This annotation is used to define that a field represents a 1-N relation. Specified on the field/method.

AttributeTypeDescriptionDefault
targetEntityClassClass at the other side of the relation
fetchbooleanWhether the field should be fetched immediatelyEAGER | LAZY
mappedByStringName of the field that owns the relation (specified on the inverse side)
cascadeCascadeType[]Whether persist, update, delete, refresh operations are cascaded
@Entity
public class Person
{
    @OneToMany
    Collection<Person> friends;
    ...
}




@ManyToMany

This annotation is used to define that a field represents a M-N relation. Specified on the field/method.

AttributeTypeDescriptionDefault
targetEntityClassClass at the other side of the relation
fetchbooleanWhether the field should be fetched immediatelyEAGER | LAZY
mappedByStringName of the field on the non-owning side that completes the relation. Specified on the owner side.
cascadeCascadeType[]Whether persist, update, delete, refresh operations are cascaded
@Entity
public class Customer
{
    @ManyToMany(mappedBy="customers")
    Collection<Supplier> suppliers;
    ...
}

@Entity
public class Supplier
{
    @ManyToMany
    Collection<Customer> customers;
    ...
}




@ManyToOne

This annotation is used to define that a field represents a N-1 relation. Specified on the field/method.

AttributeTypeDescriptionDefault
targetEntityClassClass at the other side of the relation
fetchbooleanWhether the field should be fetched immediatelyEAGER | LAZY
optionalbooleanWhether the field can store nulls.true | false
cascadeCascadeType[]Whether persist, update, delete, refresh operations are cascaded
@Entity
public class House
{
    @OneToMany(mappedBy="house")
    Collection<Window> windows;
    ...
}

@Entity
public class Window
{
    @ManyToOne
    House house;
    ...
}




@GeneratedValue

This annotation is used to define the generation of a value for a (PK) field. Specified on the field/method.

AttributeTypeDescriptionDefault
strategyGenerationTypeStrategy to use when generating the values for this field. Has possible values of GenerationType TABLE, SEQUENCE, IDENTITY, AUTO.GenerationType.AUTO
generatorStringName of the generator to use. See @TableGenerator and @SequenceGenerator
@Entity
public class Person
{
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE)
    long id;
    ...
}




@MapKey

This annotation is used to define the field in the value class that represents the key in a Map. Specified on the field/method.

AttributeTypeDescriptionDefault
nameStringName of the field in the value class to use for the key. If no value is supplied and the field is a Map then it is assumed that the key will be the primary key of the value class. JPOX only supports this null value treatment if the primary key of the value has a single field.
@Entity
public class Person
{
    @OneToMany
    @MapKey(name="nickname")
    Map<String, Person> friends;
    ...
}




@OrderBy

This annotation is used to define a field in the element class that is used for ordering the elements of the List when it is retrieved. Specified on the field/method.

AttributeTypeDescriptionDefault
valueStringName of the field(s) in the element class to use for ordering the elements of the List when retrieving them from the datastore. This is used by JPA "ordered lists" as opposed to JDO "indexed lists" (which always return the elements in the same order as they were persisted. The value will be a comma separated list of fields and optionally have ASC/DESC to signify ascending or descending
@Entity
public class Person
{
    @OneToMany
    @OrderBy(value="nickname")
    List<Person> friends;
    ...
}




@Column

This annotation is used to define the column where a field is stored. Specified on the field/method.

AttributeTypeDescriptionDefault
nameStringName for the column
uniquebooleanWhether the field is uniquetrue | false
nullablebooleanWhether the field is nullabletrue | false
insertablebooleanWhether the field is insertabletrue | false
updatablebooleanWhether the field is updatabletrue | false
tableStringName of the table
lengthintLength for the column255
precisionintDecimal precision for the column0
scaleintDecimal scale for the column0
@Entity
public class Person
{
    @Basic
    @Column(name="SURNAME", length=100, nullable=false)
    String surname;
    ...
}




@JoinColumn

This annotation is used to define the FK column for joining to another table. This is part of a 1-1, 1-N, or N-1 relation. Specified on the field/method.

AttributeTypeDescriptionDefault
nameStringName for the column
referencedColumnNameStringName of the column in the other table that this is the FK for
uniquebooleanWhether the field is uniquetrue | false
nullablebooleanWhether the field is nullabletrue | false
insertablebooleanWhether the field is insertabletrue | false
updatablebooleanWhether the field is updatabletrue | false
columnDefinitionStringSome vague JPA term that is some SQL to generate the column, but that will likely be different on all implementations. Not supported by JPOX.
@Entity
public class Person
{
    @OneToOne
    @JoinColumn(name="PET_ID", nullable=true)
    Animal pet;
    ...
}




@JoinColumns

This annotation is used to define the FK columns for joining to another table. This is part of a 1-1, 1-N, or N-1 relation. Specified on the field/method.

AttributeTypeDescriptionDefault
valueJoinColumn[]Details of the columns
@Entity
public class Person
{
    @OneToOne
    @JoinColumns({@JoinColumn(name="PET1_ID"), @JoinColumn(name="PET2_ID")})
    Animal pet; // composite PK
    ...
}




@UniqueConstraint

This annotation is used to define a unique constraint to apply to a table. It is specified as part of @Table, @JoinTable or @SecondaryTable.

AttributeTypeDescriptionDefault
columnNamesString[]Names of the column(s)
@Entity
@Table(name="PERSON", uniqueConstraints={@UniqueConstraint(columnNames={"firstName","lastName"})})
public class Person
{
    @Basic
    String firstName;

    @Basic
    String lastName;
    ...
}




@Extensions

JPOX Extension Annotation used to define a set of extensions specific to JPOX. Specified on the class or field.

AttributeTypeDescriptionDefault
valueExtension[]Array of extensions - see @Extension annotation
@Entity
@Extensions({@Extension(key="firstExtension", value="myValue"),
             @Extension(key="secondExtension", value="myValue")})
public class Person
{
    ...
}




@Extension

JPOX Extension Annotation used to define an extension specific to JPOX. Specified on the class or field.

AttributeTypeDescriptionDefault
vendorNameStringName of the vendorjpox
keyStringKey for the extension
valueStringValue of the extension
@Entity
@Extension(key="RunFast", value="true")
public class Person
{
    ...
}