簡體   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