从 JPA 注释生成 DDL

发布于 2024-10-26 22:26:44 字数 2715 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-11-02 22:26:45

您是否使用 @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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文