开发者

generate DDL from JPA annotations

开发者 https://www.devze.com 2023-02-19 16:28 出处:网络
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

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.Co开发者_运维知识库lumn(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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消