The metamodel for entity views is very similar to the JPA metamodel and the entry point is ViewMetamodel
which can be acquired through EntityViewManager.getMetamodel()
It allows access to views(ViewType
) and flat views(FlatViewType
) which both are subtypes of managed views(ManagedViewType
).
The only difference between the two is that a flat view has no id mapping, so it’s identity is composed of all attributes
which results in some limitations as described in the flat view mapping section.
interface ManagedViewType { +getJavaType() +getEntityClass() +getAttributes() +getAttribute(String name) +getDefaultBatchSize() +getConstructors() +getConstructor(Class<?>... paramTypes) +getConstructorNames() +getConstructor(String name) } interface ViewType { +getName() +getIdAttribute() +isUpdatable() +isPartiallyUpdatable() +getViewFilter(String name) +getViewFilters() } interface FlatViewType { } interface MappingConstructor { +getName() +getDeclaringType() +getJavaConstructor() +getParameterAttributes() +getParameterAttribute(int index) } interface FilterMapping { +getName() +isViewFilter() +getFilterClass() } interface ViewFilterMapping { +getDeclaringType() } ManagedViewType <|-- ViewType ManagedViewType <|-- FlatViewType FilterMapping <|-- ViewFilterMapping hide fields hide FlatViewType members
A view can have multiple named constructors that have parameter attributes. Additionally, a view can also have multiple named view filters. Every managed view has attributes which are structured based on the arity(singular or plural), the mapping type(parameter or method) and correlation type(normal, subquery or correlated).
interface Attribute { +getDeclaringType() +getJavaType() +isSubquery() +isCollection() +isSubview() +isCorrelated() +getFetchStrategy() +getBatchSize() } interface SingularAttribute { +isQueryParameter() +isId() } interface PluralAttribute { +getCollectionType() +getElementType() +isIndexed() +isOrdered() +isSorted() +getComparator() +getComparatorClass() } interface MethodAttribute { +getName() +isUpdatable() +getJavaMethod() +getFilter(String filterName) +getFilters() } interface ParameterAttribute { +getIndex() +getDeclaringConstructor() } interface MappingAttribute { +getMapping() } interface CorrelatedAttribute { +getCorrelationProvider() +getCorrelationBasis() +getCorrelationResult() } interface SubqueryAttribute { +getSubqueryProvider() +getSubqueryExpression() +getSubqueryAlias() } enum CollectionType { COLLECTION LIST MAP SET } interface CollectionAttribute interface SetAttribute interface ListAttribute interface MapAttribute { +getKeyType() +isKeySubview() } interface FilterMapping { +getName() +isViewFilter() +getFilterClass() } interface AttributeFilterMapping { +getDeclaringAttribute() } Attribute <|-- SingularAttribute Attribute <|-- PluralAttribute Attribute <|-- MethodAttribute Attribute <|-- ParameterAttribute Attribute <|-- MappingAttribute Attribute <|-- CorrelatedAttribute SingularAttribute <|-- SubqueryAttribute PluralAttribute <|-- ListAttribute PluralAttribute <|-- MapAttribute PluralAttribute <|-- CollectionAttribute PluralAttribute <|-- SetAttribute FilterMapping <|-- AttributeFilterMapping hide fields hide CollectionAttribute members hide SetAttribute members hide ListAttribute members show CollectionType fields hide CollectionType methods
An attribute is always either an instance of ParameterAttribute
or MethodAttribute
depending on whether it is defined on a constructor as parameter or as getter method.
A parameter attribute is defined by it’s index and it’s declaring MappingConstructor
.
Method attributes have a name, may have multiple named attribute filters and might possibly be updatable.
A singular attribute is always an instance of SingularAttribute
and is given if isCollection()
returns false
.
If it is a subquery i.e. isSubquery()
returns true
, it is also an instance of SubqueryAttribute
.
If it is correlated i.e. isCorrelated()
returns true
, it is also an instance of CorrelatedAttribute
.
If it is neither a subquery nor correlated, it is going to be an instance of MappingAttribute
.
A plural attribute is always an instance of PluralAttribute
and is given if isCollection()
return true
.
Since plural attributes can’t be defined via a subquery mapping, it is never an instance of SubqueryAttribute
.
If it is correlated i.e. isCorrelated()
returns true
, it is also an instance of CorrelatedAttribute
, otherwise it is going to be an instance of MappingAttribute
.
Depending on the collection type returned by getCollectionType
a plural attribute is also an instance of
-
CollectionAttribute
ifCollectionType.COLLECTION
-
ListAttribute
ifCollectionType.LIST
-
SetAttribute
ifCollectionType.SET
-
MapAttribute
ifCollectionType.MAP