Search |
|||
Lance Andersen's blogGenerating the JPA 2.0 Static MetaModel classes using Eclipselink 2.0 and Netbeans 6.8 for your Entity ClassesPosted by lancea on December 15, 2009 at 1:11 PM PST
Eclipselink 2.0 includes an annotation processor for generating the static metamodel classes from your Entity classes for use with the Criteria API which is one of the new features in JPA 2.0. Here is an example of generating the metamodel classes from the command line using the Eclipselink annotation processor:
<target name="generate-metamodel" depends="init"> A couple of notes about the target above:
Once you have added the target to the build.xml, you will want to add a menu option to make it easier to invoke the target. You can do this by: 1. Right clicking on the name of the target and "Create Shortcut"
2. Indicate that you are adding a "Menu Item"
3. Select "Refactor" for where to add the Menu Item.
Now you are ready to use the new target which you can access from the refactor menu:
The Netbeans project, CriteriaStaticMetaModelDemo, provides a simple set of examples on how to use the Criteria AP. The queries that are provided access the metamodel dynamically and statically as well as demonstrate String based navigation. The code for using the static metamodel example looks like: private void staticMetaModel() { System.out.println("***Running static metamodel Example*****");
The example creates two queries using the Criteria API. The first query will select all leagues whose gender is equal to "Mixed". Gender is a Enum. The 2nd query will return all teams whose name begins with "Longfellow". The static metamodel classes are generated by appending an "_" to the name of the entity. In the example above, League_ and Team_ are the static metamodel classes that were generated for the entities League and Team. Both queries are quite trivial but show how you can create strongly typed queries using the static metamodel. For more information on JPA 2.0: »
Comments
Comments are listed in date ascending order (oldest first)
|
ArchivesDecember 2009
April 2009 December 2008 November 2008 July 2008 January 2008 September 2007 June 2007 March 2007 December 2006 November 2006 October 2006 July 2006 June 2006 May 2006 March 2006 February 2006 December 2005 October 2005 July 2005 June 2005 April 2005 December 2004 November 2004 September 2004 July 2004 June 2004 Recent Entries |
||
|