The annotated property should be of type java.,
java., java., or
java., and the elements of the collection must be
entities.
For example:
@ManyToAny
@Column(name = "property_type")
@AnyKeyJavaClass(Long.class)
@AnyDiscriminatorValue(discriminator = "S", entity = StringProperty.class)
@AnyDiscriminatorValue(discriminator = "I", entity = IntegerProperty.class)
@JoinTable(name = "repository_properties",
joinColumns = @JoinColumn(name = "repository_id"),
inverseJoinColumns = @JoinColumn(name = "property_id"))
@Cascade(PERSIST)
private List<Property<?>> properties = new ArrayList<>();
In this example, Property is not required to be an entity type,
it might even just be an interface, but its subtypes StringProperty
and IntegerProperty must be entity classes with the same identifier
type.
This is just the many-valued form of Any, and the mapping
options are similar, except that the
@JoinTable annotation is used
to specify the association table.
AnyDiscriminator, JdbcType, or JdbcTypeCode
specifies the type of the discriminator,
AnyDiscriminatorValue specifies how discriminator values
map to entity types.
AnyKeyJavaType, AnyKeyJavaClass, AnyKeyJdbcType,
or AnyKeyJdbcTypeCode specifies the type of the foreign key.
jakarta.persistence.JoinTable specifies the name of the
association table and its foreign key columns.
jakarta.persistence.Column specifies the column of the
association table in which the discriminator value is stored.
Any
| Modifier and Type | Method and Description |
|---|---|
| public FetchType | fetch()
Specifies whether the value of the field or property should be fetched lazily or eagerly:
|
| fetch | back to summary |
|---|---|
| public FetchType fetch() Specifies whether the value of the field or property should be fetched lazily or eagerly:
| |