繁体   English   中英

JPA ORM.xml映射文件 <mapped-superclass> 不能放 <basic> 一起 <id > 要么 <version >

[英]JPA ORM.xml mapping file in <mapped-superclass> cannot put <basic> together <id > or <version >

我的JPA注释类很多,我需要将其更改为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>

如果同时具有<id>标签或<version>标签<basic>显示错误:

 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比注释有什么限制吗?

元素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元素下元素的此顺序在架构中定义:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM