我有很多带JPA Annotations的课程,我需要将其更改为orm mappingfile。
但是,XML中存在一个奇怪的错误
我的XML
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
<mapped-superclass class="model.base.BaseModel">
<entity-listeners>
<entity-listener class="model.base.BaseModelListener"></entity-listener>
</entity-listeners>
<attributes>
<id name="id">
<generated-value strategy="IDENTITY" />
</id>
<version name="version"></version>
<basic name="createdAt" optional="false">
<column name="updated_at" nullable="false" />
<temporal>TIMESTAMP</temporal>
</basic>
<basic name="updatedAt" optional="false">
<column name="updated_at" nullable="false" />
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</mapped-superclass>
<entity class="model.general.Account">
<attributes>
<basic name="email">
</basic>
</attributes>
</entity>
如果有&lt; ID&GT;标签或&lt;版本&GT;标记在一起&lt;基本&GT;显示错误:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'basic'. One of {"xmlns.jcp.org/xml/ns/persistence/orm":version "http://xmlns.jcp.org/xml/ns/persistence/orm":many- to-one, http://xmlns.jcp.org/xml/ns/persistence/orm":one-to-many, " http://xmlns.jcp.org/xml/ns/
persistence/orm":one-to-one, "http://xmlns.jcp.org/xml/ns/persistence/orm":many-to-many, "http:// xmlns.jcp.org/xml/ns/persistence/orm":element-collection, "http://xmlns.jcp.org/xml/ns/persistence/ orm":embedded, http://xmlns.jcp.org/xml/ns/persistence/orm":transient}' is expected.
怎么了? 我可以在带有注释的模型类中定义的.xml中的超类中定义属性吗? Ť
他带有注释的类是没有问题的作品,使用.xml是否有任何限制而不是注释?
答案 0 :(得分:0)
元素version
应该在最后一次出现basic
元素之后立即发生,而不是像现在这样。
在这种情况下,正确的顺序是:
<id name="id">
<generated-value strategy="IDENTITY" />
</id>
<basic name="createdAt" optional="false">
<column name="updated_at" nullable="false" />
<temporal>TIMESTAMP</temporal>
</basic>
<basic name="updatedAt" optional="false">
<column name="updated_at" nullable="false" />
<temporal>TIMESTAMP</temporal>
</basic>
<version name="version"></version>
作为旁注,列updated_at似乎被映射了两次。
attributes
元素下的元素顺序在schema中定义:
<xsd:sequence>
....
<xsd:choice>
<xsd:element name="id" type="orm:id"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="embedded-id" type="orm:embedded-id"
minOccurs="0"/>
</xsd:choice>
<xsd:element name="basic" type="orm:basic"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="version" type="orm:version"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="many-to-one" type="orm:many-to-one"
minOccurs="0" maxOccurs="unbounded"/>
....
</xsd:sequence>