Updated on July 25, 2012: The DataNucleus documentation link, pom.xml snippet.
Java EE 6 and JPA 2.0 bring us a neat feature from Hibernate: Criteria queries, which allow you to construct complex database queries in a safe manner, instead of trying to append pieces of SQL or JQL together, and hoping that the result doesn't allow injection attacks.
That's all well and good, but JPA 2.0 adds a wrinkle: instead of using simple strings to construct Criteria queries, one must generate metamodel classes, out of the entity classes. This is done by using the Java 6 APT annotation pre-processor.
Unfortunately, Maven doesn't support this kind of generation process very well out of the box. There are, however, various plugins such as the maven-annotation-plugin and apt-maven-plugin to help with this process.
I am still in the process of figuring out which way of generating the classes is the best, where they should go, and how to handle the process in a way which doesn't tie one to a specific JPA provider.
NetBeans has its own opinion on how the generated classes should be handled, as well.
Meanwhile, these are the best resources I've found for generating metamodels for various JPA implementations:
Edit: this works for me with Hibernate.