从 JPA 注释生成 DDL
我正在尝试使用 hibernate3-maven-plugin 的 hbm2ddl 目标。我在我的 pom.xml 中配置了以下内容
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hibernate-create-schema</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>jpaconfiguration</implementation>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<persistenceunit>bm-domain</persistenceunit>
<outputfilename>create.sql</outputfilename>
<drop>false</drop>
<create>true</create>
<export>false</export>
<format>true</format>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>
我的 persistence.xml 仅包含以下内容:
<persistence-unit name="bm-domain" transaction-type="RESOURCE_LOCAL">
</persistence-unit>
我已将一个 database.properties 文件添加到指定的类路径中:
hibernate.dialect=org.hibernate.dialect.MySQLDialect
当我运行 mvn install
时,我得到错误:
org.hibernate.MappingException:可以 无法确定以下类型:java.util.Set, 在表:用户,对于列:[org.hibernate.mapping.Column(兼容的AnnualEarnings)]
这似乎引用了 User 类的以下属性,
Set<AnnualEarnings> compatibleAnnualEarnings;
@Enumerated(EnumType.STRING)
AnnualEarnings annualEarnings;
AnnualEarnings 类位于用户类的包,定义如下:
public enum AnnualEarnings implements Serializable{
GROUP_1, GROUP_2, GROUP_3, GROUP_4, GROUP_5, GROUP_6, GROUP_7;
}
I'm trying to generate a DDL from a set of JPA-annotated classes using the hbm2ddl goal of the hibernate3-maven-plugin. I've configured the following in my pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hibernate-create-schema</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>jpaconfiguration</implementation>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<persistenceunit>bm-domain</persistenceunit>
<outputfilename>create.sql</outputfilename>
<drop>false</drop>
<create>true</create>
<export>false</export>
<format>true</format>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>
My persistence.xml contains just the following:
<persistence-unit name="bm-domain" transaction-type="RESOURCE_LOCAL">
</persistence-unit>
And I've added a database.properties file to the classpath that specifies:
hibernate.dialect=org.hibernate.dialect.MySQLDialect
When I run mvn install
I get the error:
org.hibernate.MappingException: Could
not determine type for: java.util.Set,
at table: user, for columns: [org.hibernate.mapping.Column(compatibleAnnualEarnings)]
which seems to refer to the following properties of the User class
Set<AnnualEarnings> compatibleAnnualEarnings;
@Enumerated(EnumType.STRING)
AnnualEarnings annualEarnings;
the AnnualEarnings
class is in a sub-package of the User class' package and is defined thus:
public enum AnnualEarnings implements Serializable{
GROUP_1, GROUP_2, GROUP_3, GROUP_4, GROUP_5, GROUP_6, GROUP_7;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用
@ElementCollection
注释您的Set
?这可能也有帮助:Persisting set of Enums in a Many-to-many uni Directionmapping
Did you annotate your
Set<AnnualEarnings>
with an@ElementCollection
?This might be helpful as well: Persisting set of Enums in a many-to-many unidirectional mapping