从JPA注释生成DDL [英] generate DDL from JPA annotations

查看:147
本文介绍了从JPA注释生成DDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 hibernate3-maven-plugin的hbm2ddl目标。我在我的pom.xml中配置了以下内容:

 < plugin> 
< groupId> org.codehaus.mojo< / groupId>
< artifactId> hibernate3-maven-plugin< / artifactId>
< version> 2.2< / version>
<执行次数>
<执行>
< id> hibernate-create-schema< / id>
<阶段>程序类< /阶段>
<目标>
< goal> hbm2ddl< / goal>
< /目标>
<配置>
<组件>
< component>
<名称> hbm2ddl< / name>
< implementation> jpa配置< / implementation>
< / component>
< /组件>
< componentProperties>
< jdk5> true< / jdk5>
< persistenceunit> bm-domain< / persistenceunit>
< outputfilename> create.sql< / outputfilename>
< drop> false< / drop>
< create> true< / create>
<导出> false< /导出>
< format> true< / format>
< / componentProperties>
< / configuration>
< /执行>
< /执行次数>
< / plugin>

我的persistence.xml包含以下内容:

 < persistence-unit name =bm-domaintransaction-type =RESOURCE_LOCAL> 
< / persistence-unit>

我添加了一个database.properties文件到类路径中,该文件指定了:

  hibernate.dialect = org.hibernate.dialect.MySQLDialect 

运行 mvn install 时出现错误:


org.hibernate.MappingException:可能
不确定类型:java.util.Set,
在表:user,for列:[org.hibernate.mapping.Column(compatibleAnnualEarnings)]


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

 组< AnnualEarnings> compatibleAnnualEarnings; 

@Enumerated(EnumType.STRING)
AnnualEarnings annualEarnings;

AnnualEarnings 包的User类'包,并定义如此:

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


解决方案

使用 @ElementCollection 来设置< AnnualEarnings> ?

这也许会有所帮助:坚持一组枚举,多对多单向映射


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;
}

解决方案

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

这篇关于从JPA注释生成DDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆