Java Reference
In-Depth Information
Using the Metamodel interface, you can then iterate over all managed classes. This is
shown in the following listing.
Listing 11.3. Introspecting the Metamodel interface dynamically at runtime
The meta-model API is extremely powerful. You can now retrieve a list of all managed en-
tities and introspect them for their attributes and relationships. This is only one piece of the
puzzle. The generated code is what you're after and what will provide you the static typing
of your queries.
Generated code
The annotation processor will generate a meta-model class for each managed entity. The
generated class will have the same name except for a _ that will be appended. The gener-
ated class will also be annotated with @Static-Metamodel . Table 11.9 documents the
definition of attributes in the meta-model class instance. The table also documents the code
generated for the different types of attributes. The Metamodel interface provides a mech-
anism for finding meta-model classes dynamically at runtime.
Table 11.9. Meta-model class attribute definitions
Meta-model declaration
Attribute type
public static volatile SingularAttribute<X, Y> y;
Noncollection attribute
public static volatile CollectionAttribute<X, Z> z;
java.util.Collection
public static volatile SetAttribute<X, Z> z;
java.util.Set
public static volatile ListAttribute<X, Z> z;
java.utilList
public static volatile MapAttribute<X, K, Z> z;
java.util.Map
The following listing shows the meta-model class generated by the annotation processor
for the Item entity class in ActionBazaar.
 
Search WWH ::




Custom Search