Table of Contents
@javax.persistence.Basic
@javax.persistence.Column
@javax.persistence.DiscriminatorValue
@javax.persistence.Embeddable
@javax.persistence.Entity
@javax.persistence.FetchType
@javax.persistence.Id
@javax.persistence.JoinColumn
@javax.persistence.ManyToOne
@javax.persistence.NamedQueries
and
@javax.persistence.NamedQuery
@javax.persistence.OneToOne
@javax.persistence.Transient
@javax.persistence.Version
This appendix describes the annotations that are identified by Naked Objects and whose semantics are captured in the Naked Objects metamodel. The presence of some of these are reflected in the Naked Objects viewers, others are required by JPA Objects itself.
Note that these are not the only annotations that can be applied; in
general most JPA/Hibernate annotations will work. However, there are a
number of annotations that are not supported, namely those that define
composite primary keys. See Section 2.3, “Specify a primary key using @Id
(not using
@IdClass
or
@EmbeddedId
)” for further
discussion.
Applies only to properties. Used by JPA to describe a simple value property.
For Naked Objects, it determines:
whether the property is mandatory or not, using
@Basic(optional=...)
the fetch type; @Basic(fetch=...)
.
This isn't used by Naked Objects viewer but is stored in the
metamodel.
Applies only to properties. Used by JPA to specify details about the column in the database table.
For Naked Objects, it determines:
whether the property is mandatory or not, using
@Column(nullable=...)
for a string property, its maximum length, using
@Column(length=...)
Applies only to classes. Used by JPA to distinguish subclass
entities (see Section B.1.5, “@javax.persistence.Entity
”) within inheritance
hierarchies.
Whereas in "regular" JPA it is only necessary to annotate
entities with inheritance, JPA Objects makes this a mandatory
requirement for all entities that are not embeddable (see Section B.1.4, “@javax.persistence.Embeddable
”). This is for two reasons:
first it helps enforce standards in the use of meta-def
strings for polymorphic relationships (see Section B.2.1, “@org.hibernate.annotations.AnyMetaDef
”).
second, it is used for the string form of the object
identifier (see Section 2.3, “Specify a primary key using @Id
(not using
@IdClass
or
@EmbeddedId
)”).
Applies to classes. Used by JPA to indicate that a class is not
standalone, in other words is embeddable within another entity (see
Section B.1.5, “@javax.persistence.Entity
”) by way of an property annotated
with @Embedded
(see Section 4.7, “Embedded Objects”).
In domain-driven design terms an embeddable object is an
aggregated object, and this semantic is captured in the Naked Objects
metamodel. In addition, JPA Objects ensures that every domain class is
annotated as either an @Entity
or
@Embeddable
.
Applies to classes, indicating that the class represents a persistent entity.
For Naked Objects,
@javax.persistence.Entity
is captured in the
metamodel and is used for validation; every domain class must be
annotated as either an @Entity
or
@Embeddable
(see Section B.1.4, “@javax.persistence.Embeddable
”). See Chapter 2, JPA Objects / Naked Objects Restrictions for more details. It isn't
otherwise used.
See also the Hibernate specific annotation, Section B.2.3, “@org.hibernate.annotations.Entity
”.
Applies to properties and collections. Used by JPA/Hibernate, to specify lazy loading characteristics.
Not used by Naked Objects, but captured in the metamodel
(primarily as a side-effect of capturing semantics by other
annotations that do provide other relevant info, eg
@org.hibernate.annotations.CollectionOfElements
,
Section B.2.2, “@org.hibernate.annotations.CollectionOfElements
”).
Applies only to properties. Used by JPA to identify the property
to use as the primary key of an entity (see Section B.1.5, “@javax.persistence.Entity
”).
In JPA every entity must be identified, and
while this is typically done using @Id
, it is
also possible to use composite keys. However, JPA Objects does
not support composite keys; every entity must be
annotated with @Id
.
The reasoning is the same as that for making discriminator
values (see Section B.1.3, “@javax.persistence.DiscriminatorValue
”)
mandatory:
first, Hibernate requires that any classes engaged in polymorphic relationships must use an Id; and such relationships are common in Naked Objects applications;
second, the Id is used for the string form of the object
identifier (see Section 2.3, “Specify a primary key using @Id
(not using
@IdClass
or
@EmbeddedId
)”).
For Naked Objects, the @Id
annotation
implies that the property is both mandatory and disabled.
Applies only to properties. Used by JPA to
specify a mapped column for joining an entity association, in other
words the name of the foreign key table for a
@ManyToOne
(Section B.1.9, “@javax.persistence.ManyToOne
”) or a @OneToOne
(Section B.1.11, “@javax.persistence.OneToOne
”) association.
For Naked Objects, determines:
whether the property is optional, using
@JoinColumn(nullable=...)
Applies only to properties. Used by JPA to represent a many-to-one (child/parent) relationship, indicating the property on a "child" entity that is a reference to the "parent" entity.
For Naked Objects, determines:
whether the property is optional, using
@ManyToOne(optional=...)
fetch type, from @ManyToOne(fetch=...)
; not
used by Naked Objects but captured in the meta-model
Both of these annotations apply only to classes, and in
particular to entities (see Section B.1.5, “@javax.persistence.Entity
”). They
define a named query/set of named queries) which return the annotated
entity, for use in repository implementations. See Chapter 5, Implementing Repositories for further details.
Applies only to properties. Used by JPA to represent a one-to-one relationship, indicating the property on a "referencing" entity to a "referenced" entity.
For Naked Objects, determines:
whether the property is optional, using
@OneToOne(optional=...)
fetch type, from @OneToOne(fetch=...)
; not used
by Naked Objects but captured in the meta-model
Applies only to properties. Used by JPA to indicate that the property is not persistent.
For Naked Objects, determines:
that the property is derived (cf a property with only a getter and no setter)
Applies only to properties. Used by JPA to specify the propert that serves as its optimistic lock value.
For Naked Objects, the @Version
annotation implies that the property is both mandatory and
disabled.
For further discussion on optimistic locking, see Section 8.1, “Optimistic Locking”.