Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenJPA映射工具MetaDataException_Java_Jpa_Orm_Persistence_Openjpa - Fatal编程技术网

Java OpenJPA映射工具MetaDataException

Java OpenJPA映射工具MetaDataException,java,jpa,orm,persistence,openjpa,Java,Jpa,Orm,Persistence,Openjpa,我正在尝试使用OpenJPA完成正向映射的过程。为此,我想使用映射工具,但我不断得到元数据异常。我提供persistence.xml以及orm.xml文件作为输入,并在类路径上编译Java类,这些类定义了orm.xml文件中的对象 我像这样运行MappingTool: java -cp /home/vic/openmdx/dev/openmdx2/jre-1.6/core/lib/openmdx-base.jar:/home/vic/Downloads/apache-openjpa-2.2.1

我正在尝试使用OpenJPA完成正向映射的过程。为此,我想使用
映射工具
,但我不断得到
元数据异常
。我提供
persistence.xml
以及
orm.xml
文件作为输入,并在类路径上编译Java类,这些类定义了
orm.xml
文件中的对象

我像这样运行MappingTool:

java -cp  /home/vic/openmdx/dev/openmdx2/jre-1.6/core/lib/openmdx-base.jar:/home/vic/Downloads/apache-openjpa-2.2.1/src/java:/home/vic/Downloads/apache-openjpa-2.2.1/openjpa-2.2.1.jar:/home/vic/Downloads/apache-openjpa-2.2.1/openjpa-all-2.2.1.jar org.apache.openjpa.jdbc.meta.MappingTool -p persistence.xml -schemaAction build orm.xml
String[] arguments = new String[] { "-action", "buildSchema", "-foreignKeys", "false", "-openjpa.Tool", "false" };
Options opts = new Options();
final String[] args = opts.setFromCmdLine(arguments);
Configurations.runAgainstAllAnchors(opts, new Configurations.Runnable() {

    @Override
    public boolean run(Options opts) throws IOException, SQLException {
        JDBCConfiguration conf = new DistributedJDBCConfigurationImpl();
        conf.setLogFactory(new NoneLogFactory());
        try {
            return MappingTool.run(conf, args, opts);
        } finally {
            conf.close();
        }
    }
});
其中编译的类文件位于
/home/vic/Downloads/apache-openjpa-2.2.1/src/java

输出如下:


这是因为
MappingTool
使用
jdbcconfigurationmpl
作为默认值。配置
MappingTool
以将数据源用于分布式配置(DistributedJDBCConfigurationMPL)

为了实现这一点,您需要从
MappingTool
复制
main
代码,并为conf创建
DistributedJDBCConfigurationMPL
,如下所示:

java -cp  /home/vic/openmdx/dev/openmdx2/jre-1.6/core/lib/openmdx-base.jar:/home/vic/Downloads/apache-openjpa-2.2.1/src/java:/home/vic/Downloads/apache-openjpa-2.2.1/openjpa-2.2.1.jar:/home/vic/Downloads/apache-openjpa-2.2.1/openjpa-all-2.2.1.jar org.apache.openjpa.jdbc.meta.MappingTool -p persistence.xml -schemaAction build orm.xml
String[] arguments = new String[] { "-action", "buildSchema", "-foreignKeys", "false", "-openjpa.Tool", "false" };
Options opts = new Options();
final String[] args = opts.setFromCmdLine(arguments);
Configurations.runAgainstAllAnchors(opts, new Configurations.Runnable() {

    @Override
    public boolean run(Options opts) throws IOException, SQLException {
        JDBCConfiguration conf = new DistributedJDBCConfigurationImpl();
        conf.setLogFactory(new NoneLogFactory());
        try {
            return MappingTool.run(conf, args, opts);
        } finally {
            conf.close();
        }
    }
});
把论点改成你自己的论点。在运行自己的工具实现之后,一切都会正常工作

String[] arguments = new String[] { "-action", "buildSchema", "-foreignKeys", "false", "-openjpa.Tool", "false" };
Options opts = new Options();
final String[] args = opts.setFromCmdLine(arguments);
Configurations.runAgainstAllAnchors(opts, new Configurations.Runnable() {

    @Override
    public boolean run(Options opts) throws IOException, SQLException {
        JDBCConfiguration conf = new DistributedJDBCConfigurationImpl();
        conf.setLogFactory(new NoneLogFactory());
        try {
            return MappingTool.run(conf, args, opts);
        } finally {
            conf.close();
        }
    }
});