使用maven和eclipse生成元模型类(JPA,Maven,Eclipse)
我正在使用 m2e (1.0.100)、Eclipse (Indigo SR1) 和 hibernate-jpamodelgen (1.1.1.Final)。
我想让 hibernate 在编译项目时从我的实体生成 Canonical 元模型。
之前我在处理非 Maven 项目时就能够做到这一点,并且我遵循了大量有关如何配置 Eclipse 项目以使用此 jar 的教程。
然而,据我所知,当使用 m2e 时,最好(强制?)让它为您进行 eclipse 配置,所以我不确定应该如何完成。
这个hibernate教程解释了如何使用生成器与 Maven 和 Eclipse 但分开。
我认为我缺少的是粘合我的 pom(它是作为简单的无原型 pom 生成的)和我的 eclipse 项目配置,以便它们使我能够执行一些 JPA 魔法。
顺便说一句,遵循上述 maven 教程导致我的 maven 生成的 jar 包含 _ 类,但 eclipse 看不到这些类,因为它们仅在 jar 中而不是在实际项目中。
提前致谢
I'm using m2e (1.0.100), Eclipse (Indigo SR1) and hibernate-jpamodelgen (1.1.1.Final).
I want to have hibernate generate the Canonical metamodel from my entities when I compile the projects.
I was able to do this previously when I was working on a non-maven project and I followed the numerous tutorials there are on how to configure the eclipse project to use this jar.
However, to the best of my understanding, when using m2e it is best (mandatory?) to let it do the eclipse configuration for you and so I'm not sure how this should be done.
This hibernate tutorial explains how to use the generator with maven and eclipse but separately.
I think what I'm missing is gluing my pom, which was generated as a simple no archetype pom, and my eclipse project configuration so that they enable me to do some JPA magic.
BTW, following the above tutorial for maven caused my maven-generated jars to contain the _ classes but these are not seen by eclipse since they are only in the jars and not in the actual projects.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 m2e-users 邮件列表上问了同样的问题,并得到了以下答案(链接对于那些想要完整线程的人):
基本上应该手动配置(例如使用上面提到的hibernate教程)eclipse来使用生成器并配置maven使用的相同目录(对我来说,它是 target/ generated-sources/annotations )作为输出目录。
根据 m2e 的提交者的说法,该项目当前不会更改这些 eclipse 文件,因此不会被它们覆盖。
我确实面临的问题是,当使用 GIT 并在分支之间切换时,此信息丢失(因此再次需要手动更改),因为我不想将任何 eclipse 相关文件提交到 SCM。
目前这是一个可以接受的解决方案,我希望 m2e 能够添加这个缺失的功能。
更新
至少根据我的经验,丢失的信息是将
target/ generated-sources/annotations
文件夹定义为源文件夹。仅供参考。I've asked the same question on the m2e-users mailing list and got the following answer (link for those wanting the full thread):
Basically one should manually configure (for example using the above mentioned hibernate tutorial) eclipse to use the generator and configure the same directory maven uses (for me it was target/generated-sources/annotations) as the output directory.
According to the committers of m2e, the project currently does not change these eclipse files and so this won't be overriden from them.
The problem I did face was that this information is lost (and so the manual change is needed again) when using GIT and switching between branches as I don't want to commit any eclipse related files to the SCM.
Currently this is an acceptable solution and I hope m2e will be able to add this missing feature.
Update
The information that is lost, at least according to my experience, is the definition of the
target/generated-sources/annotations
folder as a source folder. Just as an FYI.