简体   繁体   中英

Sub-packaging my static meta-model classes on Eclipse Indigo

I'm currently using Eclipse Indigo and I'd like to have my meta-model classes to be automatically generated in a sub-package instead of having them in the same package of my entities.

I've followed the instructions in the JPA User Guide for Canonical Model Generator on Eclipse Galileo, but it's not working at all with Indigo. :(

Does anybody use the static meta-model classes in a sub-package? Is there any way to configure it on Eclipse Indigo?

Maybe you should not change package
I would suggest against it, because having those in sub package (or any other) violates current JPA 2 specification:

• For each managed class X in package p, a metamodel class X_ in package p is created.[67]
...
[67] We expect that the option of different packages will be provided in a future release of this specification.
...
Implementations of this specification are not required to support the use of non-canonical metamodel classes. Applications that use non-canonical metamodel classes will not be portable.

Other way to organize is common JUnit practice: same package in different source directory.

But if you have to, this is how it is done

Following works at least with Eclipse version: Indigo Service Release 1 20110916-0149 and EclipseLink: eclipselink-2.3.0.v20110604-r9504. Names of the JARs can slightly vary from version to another.

If enabled, disable generating to the same package where entities are:

  1. Go to Project Properties - JPA and check that value of Source Folder is <None>

Adjusting generating to the other package:

  1. Properties - Annotation Processing
    [x] Enable project specific settings
    [x] Enable annotation processing
    [x] Enable processing in editor
    Generated source directory: src (or wherever sources live)
  2. New processor option:
    key= eclipselink.canonicalmodel.subpackage
    value= sub | (desired package name)
  3. Go one level deeper to the Annotation Processing | Factory Path and select Add External JARs and add following jars:
    eclipselink/jlib/jpajavax.persistence_2.0.3.v201010191057.jar
    eclipselink/jlib/jpaeclipselink-jpa-modelgen_2.3.0.v20110604-r9504.jar
    eclipselink/jlib/eclipselink.jar
  4. Let Eclipse rebuild project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM