无法从JPA注释类生成DDL

时间:2015-10-06 21:05:16

标签: hibernate jpa maven-plugin ddl jpa-annotations

我有一个示例java项目,处于原型阶段,我需要从JPA注释类创建DDL。需要使用hibernate,Mysql。由于某些公司原因,我的项目不是Maven项目。但我在系统上安装了Maven。 所以我根据这里提供的许多解决方案创建了一个pom.xml,并将其放在我的项目文件夹中。我试图运行 mvn hibernate3:hbm2ddl 但我得到了以下错误。

INFO] ------------------------------------------------------------------------
INFO] BUILD FAILURE
INFO] ------------------------------------------------------------------------
INFO] Total time: 2.059 s
INFO] Finished at: 2015-10-06T16:15:45-04:00
INFO] Final Memory: 5M/15M
INFO] ------------------------------------------------------------------------
ERROR] No plugin found for prefix 'hibernate3' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users
qxk0996.MUC\.m2\repository), central (https://repo.maven.apache.org/maven2)]

我的pom看起来像是

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.abcd</groupId>
    <artifactId>ft</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>ft Jersey Webapp</name>
    <build>
        <finalName>ft</finalName>
        <plugins>
            <plugin>
                <!-- run "mvn hibernate3:hbm2ddl" to generate a schema -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <components>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>jpaconfiguration</implementation>
                        </component>
                    </components>
                    <componentProperties>
                        <persistenceunit>ft-jpa</persistenceunit>
                        <outputfilename>schema.ddl</outputfilename>
                        <drop>false</drop>
                        <create>true</create>
                        <export>false</export>
                        <format>true</format>
                    </componentProperties>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.12</version>
        </dependency>
    </dependencies>
</project>

我在webcontent / META-INF文件夹中有persistence.xml,如下所示。

 <persistence>
        <persistence-unit name="ft-jpa">
            <description>Ft Persistence Unit</description>
                <properties>
                <property name="javax.persistence.jdbc.url" value="-----" />
        <property name="javax.persistence.jdbc.user" value="-----" />
        <property name="javax.persistence.jdbc.password" value="-----" />
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            </properties>
        </persistence-unit>
    </persistence>

1 个答案:

答案 0 :(得分:1)

我相信您只需将javax.persistence.schema-generation.scripts.action属性添加到persistence.xml文件即可。可能的值为“none”,“create”,“drop-and-create”和“drop”。

相关问题