Java Reference
In-Depth Information
The steps for using a meta-model are as follows:
1 . Annotate your POJOs using the JPA annotations.
2 . Compile the code with the meta-model processor as part of the compile process.
3 . Code criteria queries using the generated classes.
4 . Repeat as the model changes.
Annotation processor
You'll have to configure your build process and possibly your IDE to use the meta-model
processor. Consult the documentation for your JPA provider for more information. If you
don't plan on using criteria queries, no action is needed on your part. The model will be
automatically generated at deployment.
Introspection APIs
At the heart of the meta-model APIs is the Metamodel interface. You acquire a reference
to the Metamodel implementation by calling getMetamodel() on the EntityMan-
ager . You can request a specific entity or get a list of all managed entities. Information on
each entity is encapsulated in an EntityType . An EntityType has methods for get-
ting additional information about the entity, including attribute information. If you've used
Java reflection previously, this will be relatively straightforward.
The Metamodel interface is shown in the next listing. It leverages Java Generics to elim-
inate the need for casting.
Listing 11.2. Metamodel interface
Search WWH ::




Custom Search