Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/JPA 2.0/canonical model generation"

Line 74: Line 74:
 
#Ensure you have a persistence.xml. The default is META-INF/persistence.xml. If your persistence XML file is named differently or located elsewhere, you'll need to add the eclipselink.persistencexml processor option.  
 
#Ensure you have a persistence.xml. The default is META-INF/persistence.xml. If your persistence XML file is named differently or located elsewhere, you'll need to add the eclipselink.persistencexml processor option.  
 
#If you are using an extended eclipselink orm mapping file and it is not listed in your persistence.xml file, it will not be discovered similarly to the orm.xml file. You must specify <mapping-file>eclipselink-orm.xml</mapping-file> explicitly. This behavior will be corrected in a later version, that is, the eclipselink-orm.xml will be discovered automatically (as it currently does in regular deployment)
 
#If you are using an extended eclipselink orm mapping file and it is not listed in your persistence.xml file, it will not be discovered similarly to the orm.xml file. You must specify <mapping-file>eclipselink-orm.xml</mapping-file> explicitly. This behavior will be corrected in a later version, that is, the eclipselink-orm.xml will be discovered automatically (as it currently does in regular deployment)
 +
 +
After an XML change (within Eclipse), the generated model classes are not updated to reflect the change
 +
 +
#Unlike changes to the model class itself, XML changes are not picked up automatically as the annotation processor is not aware of these changes. To have your XML changes reflected in your generated metamodel classes do a clean of your project. Select '''Project''' - '''Clean...'''
  
 
== Work schedule ==
 
== Work schedule ==
  
 
== Future ==
 
== Future ==

Revision as of 08:58, 20 October 2009

Canonical model generation

JPA 2.0 Root | bug 267391

Discussion

Issue Summary

With the new Criteria API from the JPA 2.0 spec, EclipseLink will provide a way to produce static metamodel classes corresponding to the entities, mapped superclasses, and embeddable classes in the persistence unit. A static metamodel class models the persistent state and relationships of the corresponding managed class.

For portability, EclipseLink will generate the canonical metamodel as defined in section 6.2.1.1.

General solution

EclipseLink will employ the annotation processor tool (APT) in conjunction with its existing metadata processing of annotations and XML to generate the static metamodel classes.

For more information on APT, see: http://java.sun.com/j2se/1.5.0/docs/guide/apt/GettingStarted.html

Metadata processing

Internal processing details not available at this time ...

Configuring and using within Eclipse Galileo

The following steps outline how to configure the metamodel generation within the Eclipse IDE.

  1. Select Project - Properties
  2. Select Java Compiler and ensure you are using JDK 1.6+
  3. Expand Java Compiler and select Annotation Processing.
  4. On the right, select the checkbox Enable annotation processing
  5. In the text box for Generated Source Directory enter the name of the directory to which you would like to generate the metamodel classes
  6. By default, Processor options are not needed. However, EclipseLink provides you with custom generation options if you would like to configure you metamodel classes differently then defined in the spec. See section ?? for valid processor options that can be used.
  7. Expand Annotation Processing and select Factory Path
    1. Here you must add three libraries/jars for the processor to work (see 1.2.0 RC4 Library names below):
      1. The eclipselink.jar
      2. The java persistence 2.0 preview jar
      3. A special jar containing an enabling services file that specifies the name of the annotation processor tool.

Configuring and using within ANT

EclipseLink custom processor options

  • eclipselink.persistencexml

This optional property specifies the full resource name to look for the persistence XML files in. If not specified the default META-INF/persistence.xml will be used.

  • eclipselink.persistenceunits

This optional property specifies the set of persistence unit names that will be used when generating the canonical model. By default all persistence units available in all persistence XML files will be used. The value of this property is a comma separated list. When specifying multiple persistence units it is not possible to have persistence units with a comma in their name.

  • eclipselink.canonicalmodel.prefix

This optional property specifies the prefix that will be added to the start of the class name of any canonical model class generated. By default the prefix is not used.

  • eclipselink.canonicalmodel.suffix

This optional property specifies the suffix that will be added to the end of the class name of any canonical model class generated. By default the suffix value is "_". If this property is specified the value must be a non-empty string that contains valid characters for use in a Java class name.

  • eclipselink.canonicalmodel.subpackage

This optional property specifies a sub-package name that can be used to have the canonical model generator generate its classes in a sub-package of the package where the corresponding entity class is located. By default the canonical model classes are generated into the same package as the entity classes.

1.2.0 RC4 Library names

Currently the target release of EclipseLink 1.2.0 is RC4 which uses the following jar files names in the ZIP installer. Please note that the ZIP installer is the only distribution of EclipseLink including the modelgen JAR file.

  1. Services file (enables the processor).

\eclipselink\jlib\jpa\eclipselink-jpa-modelgen_1.2.0.v20091016-r5565.jar

  1. javax.persistence library

\eclipselink\jlib\jpa\javax.persistence_2.0_preview.jar

  1. EclipseLink jar

\eclipselink\jlib\eclipselink.jar

Troubleshooting

After following the configuration steps above if no classes are generated, check the following.

  1. Ensure you have a persistence.xml. The default is META-INF/persistence.xml. If your persistence XML file is named differently or located elsewhere, you'll need to add the eclipselink.persistencexml processor option.
  2. If you are using an extended eclipselink orm mapping file and it is not listed in your persistence.xml file, it will not be discovered similarly to the orm.xml file. You must specify <mapping-file>eclipselink-orm.xml</mapping-file> explicitly. This behavior will be corrected in a later version, that is, the eclipselink-orm.xml will be discovered automatically (as it currently does in regular deployment)

After an XML change (within Eclipse), the generated model classes are not updated to reflect the change

  1. Unlike changes to the model class itself, XML changes are not picked up automatically as the annotation processor is not aware of these changes. To have your XML changes reflected in your generated metamodel classes do a clean of your project. Select Project - Clean...

Work schedule

Future

Back to the top