繁体   English   中英

从JPA批注生成DDL

[英]generate DDL from JPA annotations

我正在尝试使用hibernate3-maven-plugin的hbm2ddl目标从一组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,在表:user处,用于列:[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;
}

您是否使用@ElementCollection注释了Set<AnnualEarnings>

这也可能会有所帮助: 在多对多单向映射中保留枚举集

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM