Annotation Type Any
-
@Target({METHOD,FIELD}) @Retention(RUNTIME) public @interface Any
Maps a to-one cardinality association taking values over several entity types which are not related by the usual entity inheritance, using a discriminator value stored on the referring side of the relationship.This is quite different to discriminated inheritance where the discriminator is stored along with the referenced entity hierarchy.
For example, consider an
Order
entity containingPayment
information, where aPayment
might be aCashPayment
or aCreditCardPayment
. An@Any
mapping would store the discriminator value identifying the concrete type ofPayment
along with the state of the associatedOrder
, instead of storing it with thePayment
entity itself.In this example,
Payment
would not be declared as an entity type, and would not be annotated@Entity
. It might even be an interface, or at most just a mapped superclass, ofCashPayment
andCreditCardPayment
. So in terms of the object/relational mappings,CashPayment
andCreditCardPayment
would not be considered to participate in the same entity inheritance hierarchy.It's reasonable to think of the "foreign key" in an
Any
mapping is really a composite value made up of the foreign key and discriminator taken together. Note, however, that this composite foreign key is only conceptual and cannot be declared as a physical constraint on the relational database table.AnyDiscriminator
,JdbcType
, orJdbcTypeCode
specifies the type of the discriminator.AnyDiscriminatorValues
specifies how discriminator values map to entity types.Column
orFormula
specifies the column or formula in which the discriminator value is stored.AnyKeyJavaType
,AnyKeyJavaClass
,AnyKeyJdbcType
, or orAnyKeyJdbcTypeCode
specifies the type of the foreign key.JoinColumn
specifies the foreign key column.
Any
mappings are disfavored, except in extremely special cases, since it's much more difficult to enforce referential integrity at the database level.- See Also:
ManyToAny
-
-
Element Detail
-
fetch
jakarta.persistence.FetchType fetch
Defines whether the value of the field or property should be lazily loaded or must be eagerly fetched. The EAGER strategy is a requirement on the persistence provider runtime that the value must be eagerly fetched. The LAZY strategy is applied when bytecode enhancement is used. If not specified, defaults to EAGER.- Default:
- jakarta.persistence.FetchType.EAGER
-
-