Package org.hibernate.annotations
Annotation Type ManyToAny
-
@Target({METHOD,FIELD}) @Retention(RUNTIME) public @interface ManyToAny
Maps a to-many cardinality association taking values over several entity types which are not related by the usual entity inheritance, using a discriminator value stored in an association table.The annotated property should be of type
List,Set,Collection, orMap, 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,
Propertyis not required to be an entity type, it might even just be an interface, but its subtypesStringPropertyandIntegerPropertymust 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@JoinTableannotation is used to specify the association table.AnyDiscriminator,JdbcType, orJdbcTypeCodespecifies the type of the discriminator,AnyDiscriminatorValuespecifies how discriminator values map to entity types.AnyKeyJavaType,AnyKeyJavaClass,AnyKeyJdbcType, orAnyKeyJdbcTypeCodespecifies the type of the foreign key.JoinTablespecifies the name of the association table and its foreign key columns.Columnspecifies the column of the association table in which the discriminator value is stored.
- See Also:
Any
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description FetchTypefetchSpecifies whether the value of the field or property should be fetched lazily or eagerly:FetchType.EAGER, the default, requires that the association be fetched immediately, butFetchType.LAZYis a hint which has no effect unless bytecode enhancement is enabled.
-
-
-
Element Detail
-
fetch
FetchType fetch
Specifies whether the value of the field or property should be fetched lazily or eagerly:FetchType.EAGER, the default, requires that the association be fetched immediately, butFetchType.LAZYis a hint which has no effect unless bytecode enhancement is enabled.
- Default:
- jakarta.persistence.FetchType.EAGER
-
-