【发布时间】:2011-07-18 06:34:13
【问题描述】:
我正在使用 hbm2java (hibernate3-maven-plugin) 来生成实体。
如何将自动生成的@EmbeddedId 切换为@IdClass?
谢谢
【问题讨论】:
标签: hibernate jpa reverse-engineering hibernate-tools hbm2java
我正在使用 hbm2java (hibernate3-maven-plugin) 来生成实体。
如何将自动生成的@EmbeddedId 切换为@IdClass?
谢谢
【问题讨论】:
标签: hibernate jpa reverse-engineering hibernate-tools hbm2java
hibernate maven 插件不会自动执行此操作,如果您想使用@IdClass,则需要手动更新您的类。
【讨论】:
我没有尝试关注。但是从我一直在使用 Hibernate 逆向工程工具的情况来看,我认为使用 reveng.xml 文件应该是可能的。 在你的 pom 文件中。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
</component>
</components>
<componentProperties>
<revengfile>/src/main/resources/reveng/model.reveng.xml</revengfile>
</componentProperties>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
</executions>
并在 reveng.xml 中指定映射到 IdClass 的类型(请参阅 Hibernate 工具文档 http://docs.jboss.org/tools/3.1.0.GA/en/hibernatetools/html_single/index.html#type_map 或 http://docs.jboss.org/tools/3.1.0.GA/en/hibernatetools/html_single/index.html#d0e5869)。
如前所述,我没有尝试过。
由于其他各种原因,我放弃了使用逆向工程。一个问题是hibernate 工具不兼容Hibernate 3.5 及更高版本。此外,Maven 插件是第三方的,它使用的 Hibernate 工具的版本比一般可用的工具要旧。所以我也遇到了不得不从Maven调用ant来做逆向工程的情况。
【讨论】: