@Target(value={METHOD,FIELD}) @Retention(value=RUNTIME) public @interface Any
Defines a ToOne-style association pointing to one of several entity types depending on a local discriminator, as opposed to discriminated inheritance where the discriminator is kept as part of the entity hierarchy.
For example, if you consider an Order entity containing Payment information where Payment might be of type CashPayment or CreditCardPayment the @Any approach would be to keep that discriminator and matching value on the Order itself. Thought of another way, the "foreign-key" really is made up of the value and discriminator (there is no physical foreign key here as databases do not support this): <blockquote><pre> @Entity class Order { … @Any( metaColumn = @Column( name="payment_type" ) ) @AnyMetDef( idType = "long" metaValues = { @MetaValue( value="C", targetEntity=CashPayment.class ), @MetaValue( value="CC", targetEntity=CreditCardPayment.class ), } ) pubic Payment getPayment() { … } } } </pre></blockquote>
AnyMetaDef
Modifier and Type | Required Element and Description |
---|---|
Column |
metaColumn
Identifies the discriminator column.
|
Modifier and Type | Optional Element and Description |
---|---|
FetchType |
fetch
Defines whether the value of the field or property should be lazily loaded or must be
eagerly fetched.
|
String |
metaDef
Metadata definition used.
|
boolean |
optional
Whether the association is optional.
|
public abstract Column metaColumn
Identifies the discriminator column. This column will hold the value that identifies the targeted entity.
public abstract String metaDef
Metadata definition used. If defined, should point to a @AnyMetaDef name If not defined, the local (ie in the same field or property) @AnyMetaDef is used
public abstract 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.
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.