简体   繁体   English

在Eclipse Indigo上分包我的静态元模型类

[英]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. 我目前正在使用Eclipse Indigo,并且希望将我的元模型类自动生成在子包中,而不是将它们放在实体的同一包中。

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. 我已经遵循了Eclipse Galileo上《 JPA用户规范模型生成器用户指南》中的说明,但是Indigo根本无法使用它。 :( :(

Does anybody use the static meta-model classes in a sub-package? 是否有人在子包中使用静态元模型类? Is there any way to configure it on Eclipse Indigo? 有什么方法可以在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: 我建议不要这样做,因为将它们放在子软件包(或任何其他软件包)中会违反当前的JPA 2规范:

• For each managed class X in package p, a metamodel class X_ in package p is created.[67] •对于包p中的每个托管类X,将创建包p中的元模型类X _。[67]
... ...
[67] We expect that the option of different packages will be provided in a future release of this specification. [67]我们希望在本规范的将来版本中将提供不同软件包的选项。
... ...
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. 另一种组织方式是JUnit的常见做法:同一包位于不同的源目录中。

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. 以下功能至少适用于Eclipse版本:Indigo Service Release 1 20110916-0149和EclipseLink:eclipselink-2.3.0.v20110604-r9504。 Names of the JARs can slightly vary from version to another. 每个版本的JAR名称可能略有不同。

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> 转到“项目属性-JPA”,并检查“源文件夹”的值是否为“ <None>

Adjusting generating to the other package: 将生成调整为其他包:

  1. Properties - Annotation Processing 属性-注释处理
    [x] Enable project specific settings [x]启用项目特定的设置
    [x] Enable annotation processing [x]启用注释处理
    [x] Enable processing in editor [x]在编辑器中启用处理
    Generated source directory: src (or wherever sources live) 生成的源目录:src(或存在源的任何地方)
  2. New processor option: 新的处理器选项:
    key= eclipselink.canonicalmodel.subpackage 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: 工厂路径,然后选择添加外部JAR,然后添加以下jar:
    eclipselink/jlib/jpajavax.persistence_2.0.3.v201010191057.jar eclipselink / jlib / jpajavax.persistence_2.0.3.v201010191057.jar
    eclipselink/jlib/jpaeclipselink-jpa-modelgen_2.3.0.v20110604-r9504.jar eclipselink / jlib / jpaeclipselink-jpa-modelgen_2.3.0.v20110604-r9504.jar
    eclipselink/jlib/eclipselink.jar eclipselink / jlib / eclipselink.jar
  4. Let Eclipse rebuild project. 让Eclipse重建项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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