无法使OpenJPA工具从命令行运行

时间:2019-03-16 09:47:09

标签: openjpa

我做了什么:

  • 下载并解压缩最新的openjpa版本(3.0.0)

  • 下载mariadb jdbc驱动程序jar并将其复制到openjpa-all-3.0.0.jar所在的目录中

  • 在同一目录中,创建一个包含以下内容的子目录META_INF和文件META-INF / persistence.xml:

    <?xml version="1.0"?>
    <persistence version="1.0">
    <persistence-unit name="openjpa">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <properties>
            <property name="openjpa.ConnectionURL" value="jdbc:mariadb://localhost:3306/databasename"/>
            <property name="openjpa.ConnectionDriverName" value="org.mariadb.jdbc.Driver"/>
            <property name="openjpa.ConnectionUserName" value="dbuser"/>
            <property name="openjpa.ConnectionPassword" value="dbpassword"/>
            <property name="openjpa.DynamicEnhancementAgent" value="false"/>
            <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
            <property name="openjpa.Log" value="SQL=TRACE"/>
            <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=120, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000"/>
        </properties>
    </persistence-unit>
    

  • 创建一个空目录src作为openjpa和mariadb驱动程序jar所在的子目录

  • 运行以下命令:

    java -cp ./:openjpa-all-3.0.0.jar:mariadb-java-client-2.4.0.jar:openjpa-all-3.0.0.jar org.apache.openjpa.jdbc.meta。 ReverseMappingTool -pkg some.package -d ./src

我没有得到任何输出或与生成有关的错误,而是得到了:

8  INFO   [main] openjpa.Tool - The reverse mapping tool will run on the database.  The tool is gathering schema information; this process may take some time.  Enable the org.apache.openjpa.jdbc.Schema logging category to see messages about schema data.
Exception in thread "main" <openjpa-3.0.0-r422266:1833209 fatal user error> org.apache.openjpa.util.UserException: The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database Connectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@f248234b". 
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:71)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:850)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:733)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource(JDBCConfigurationImpl.java:879)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource2(JDBCConfigurationImpl.java:921)
        at org.apache.openjpa.jdbc.schema.SchemaGenerator.<init>(SchemaGenerator.java:86)
        at org.apache.openjpa.jdbc.meta.ReverseMappingTool.run(ReverseMappingTool.java:2027)
        at org.apache.openjpa.jdbc.meta.ReverseMappingTool.run(ReverseMappingTool.java:2005)
        at org.apache.openjpa.jdbc.meta.ReverseMappingTool.run(ReverseMappingTool.java:1882)
        at org.apache.openjpa.jdbc.meta.ReverseMappingTool$1.run(ReverseMappingTool.java:1863)
        at org.apache.openjpa.lib.conf.Configurations.launchRunnable(Configurations.java:762)
        at org.apache.openjpa.lib.conf.Configurations.runAgainstAllAnchors(Configurations.java:747)
        at org.apache.openjpa.jdbc.meta.ReverseMappingTool.main(ReverseMappingTool.java:1858)

我在做什么错了?

我尝试通过在命令行中添加-p persistence.xml#openjpa,-p #openjpa和-connectionDriverName org.mariadb.jdbc.Driver来实现此目的,但是没什么区别。

0 个答案:

没有答案