我正在尝试使用OpenJPA进行前向映射过程。我想为此目的使用MappingTool
,但我继续获得MetaDataException
。我提供了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
编译的类文件位于/home/vic/Downloads/apache-openjpa-2.2.1/src/java
。
输出是这样的:
32 openjpa INFO [main] openjpa.jdbc.JDBC - Using dictionary class org.apache.openjpa.jdbc.sql.MySQLDictionary". 106 openjpa INFO [main] openjpa.Tool - Mapping tool running on type "class org.test.classdiag.jpa3.Animal" with action "buildSchema". 407 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.Attribute$Slice" 412 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.StructureField$Slice" 441 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.Reference$Slice" 455 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.Parameter$Slice" 465 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.Constant$Slice" 504 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.Import$Slice" 515 openjpa WARN [main] openjpa.Runtime - Found no persistent property in "org.omg.model1.jpa3.Constraint$Slice" Exception in thread "main" <openjpa-2.2.1-r422266:1396819 fatal user error> org.apache.openjpa.util.MetaDataException: Type "class org.test.classdiag.jpa3.Animal" loaded by sun.misc.Launcher$AppClassLoader@54f690e4 does not have persistence metadata. at org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:688) at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:754) at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:652) at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:1087) at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:1001) at org.apache.openjpa.jdbc.meta.MappingTool$1.run(MappingTool.java:937) at org.apache.openjpa.lib.conf.Configurations.launchRunnable(Configurations.java:748) at org.apache.openjpa.lib.conf.Configurations.runAgainstAllAnchors(Configurations.java:738) at org.apache.openjpa.jdbc.meta.MappingTool.main(MappingTool.java:932)
我的persistence.xml:
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="openjpa" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>org.test.classdiag.jpa3.Animal</class>
<class>org.test.classdiag.jpa3.Cat</class>
<class>org.test.classdiag.jpa3.Dog</class>
<properties>
<property name="openjpa.Log" value="SQL=TRACE"/>
<!-- <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" /> -->
<property name="openjpa.jdbc.MappingDefaults" value="IndexLogicalForeignKeys=false,IndexDiscriminator=false"/>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/TEST_OPENMDX"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value="root"/>
</properties>
</persistence-unit>
</persistence>
我的orm.xml
Animal
:
<access>FIELD</access>
<entity class="org.test.classdiag.jpa3.Animal">
<table name="OTT0CLAG_ANIMAL"/>
<inheritance strategy="JOINED"/>
<discriminator-value>org:test:classdiag:Animal</discriminator-value>
<discriminator-column name="DTYPE" discriminator-type="STRING"/>
<attributes>
<basic name="colour">
<column name="COLOUR" nullable="true"/>
</basic>
<basic name="breed">
<column name="BREED" nullable="true"/>
</basic>
<basic name="name">
<column name="NAME" nullable="true"/>
</basic>
<one-to-many name="openmdxjdoSlices" mapped-by="openmdxjdoIdentity">
<map-key name="openmdxjdoIndex"/>
</one-to-many>
</attributes>
</entity>
答案 0 :(得分:0)
这是因为MappingTool
使用JDBCConfigurationImpl
作为默认设置。配置MappingTool
以使用分布式配置的数据源(DistributedJDBCConfigurationImpl)。
为了实现这一目标,您需要复制来自main
的{{1}}代码并为此设置MappingTool
:
DistributedJDBCConfigurationImpl
并将参数更改为您自己的参数。运行自己的工具实现后,一切都会正常工作。