0

我有一个示例 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>
4

1 回答 1

1

我相信您可以将javax.persistence.schema-generation.scripts.action属性添加到 persistence.xml 文件中。可能的值是“none”、“create”、“drop-and-create”和“drop”。

于 2015-10-07T10:05:33.050 回答