Java OpenJPA映射工具MetaDataException
我正在尝试使用OpenJPA完成正向映射的过程。为此,我想使用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
映射工具
,但我不断得到元数据异常
。我提供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();
}
}
});