【问题标题】:JPA one-to-one mapping gives sax parse exceptionJPA 一对一映射给出 sax 解析异常
【发布时间】:2011-11-29 09:12:51
【问题描述】:

我在尝试在 JPA 中映射一对一关系时遇到 org.xml.sax.SAXParseException

一切正常,直到我改变

<transient name="testCase"/>

到:

<attributes>
..
    <one-to-one name="testCase">
        <join-column name="test_case_id"/>
    </one-to-one>
..
</attributes>

给出错误:

原因:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:发现从元素“一对一”开始的无效内容。 '{"http://java.sun.com/xml/ns/persistence/orm":many-to-many, "http://java.sun.com/xml/ns/persistence/orm" 之一:嵌入,“http://java.sun.com/xml/ns/persistence/orm”:transient}' 是预期的。

我不明白异常消息的含义。为什么会出现这些?

【问题讨论】:

    标签: jpa orm one-to-one


    【解决方案1】:

    根据其 XML 架构,您的 orm.xml 无效。问题是元素“一对一”是序列的一部分,这意味着包含的元素必须遵守定义的顺序。

    架构摘要:

      <xsd:complexType name="attributes">
        <xsd:sequence>
          ...
          <xsd:element name="basic" .../>
          <xsd:element name="version" .../>
          <xsd:element name="many-to-one" .../>
          <xsd:element name="one-to-many" .../>
          <xsd:element name="one-to-one" .../>
          <xsd:element name="many-to-many" .../>
          ...
        </xsd:sequence>
      </xsd:complexType>
    

    enter link description here查看整个架构

    【讨论】:

      【解决方案2】:

      我发现了问题。我移动了一对一部分,所以它位于多对多部分之前。不知道为什么会这样。这两个部分没有任何共同之处。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-22
        • 2012-11-28
        • 1970-01-01
        • 2021-11-04
        • 1970-01-01
        • 2011-08-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多