【问题标题】:generate DDL from JPA annotations从 JPA 注释生成 DDL
【发布时间】:2011-07-23 07:55:24
【问题描述】:

我正在尝试使用 hibernate3-maven-plugin 的 hbm2ddl goal 从一组 JPA 注释类生成 DDL。我在 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(compatibleAnnualEarnings)]

这似乎是指User类的以下属性

Set<AnnualEarnings> compatibleAnnualEarnings;   

@Enumerated(EnumType.STRING)
AnnualEarnings annualEarnings;

AnnualEarnings 类位于 User 类的包的子包中,其定义如下:

public enum AnnualEarnings implements Serializable{
    GROUP_1, GROUP_2, GROUP_3, GROUP_4, GROUP_5, GROUP_6, GROUP_7;
}

【问题讨论】:

    标签: java hibernate maven-2 jpa


    【解决方案1】:

    您是否使用@ElementCollection 注释了您的Set&lt;AnnualEarnings&gt;

    这也可能有帮助:Persisting set of Enums in a many-to-many unidirectional mapping

    【讨论】:

    猜你喜欢
    • 2016-01-03
    • 2019-03-25
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    • 2011-01-03
    • 2013-10-12
    • 2011-08-24
    相关资源
    最近更新 更多