xml - hibernate 一对多列表映射错误

标签 xml hibernate mapping

我有以下 hibernate xml 映射文件段。

   

    <list name="networks" cascade="all">
                <key column="parent_id"/>    

                <one-to-many class="Network"/>
        </list>

它产生了以下异常,为什么?它确实具有上述元素。

Caused by: org.xml.sax.SAXParseException: The content of element type "list" must match "(meta*,subselect?,cache?,synchronize*,comment?,key,(index|list-index),(element|one-to-many|many-to-many|composite-element|many-to-any),loader?,sql-insert?,sql-update?,sql-delete?,sql-delete-all?,filter*)".
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    at org.hibernate.cfg.Configuratio

最佳答案

您需要添加 <list-index对于 <List > 是强制性的映射。

<list name="networks" cascade="all">
    <key column="parent_id"/>    
    <list-index column="order" base="0" />
    <one-to-many class="Network"/>
</list>

hibernate 引用文档

6.2.3. Indexed collections
All collection mappings, except those with set and bag semantics, need an index column in the collection table. An index column is a column that maps to an array index, or List index, or Map key.

关于xml - hibernate 一对多列表映射错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7033159/

相关文章:

java - Hibernate 序列化异常

mysql - 在 MySQL 数据库中存储纬度/经度时使用的理想数据类型是什么?

java - 使用 Hibernate 将 Oracle 日期映射到 Java 对象

java - 在 swing 表单中点击按钮时生成 xml

android - 尝试测试 AnimatedVectorDrawable 时出错, "Can' t 从 x 到 z 变形”

postgresql - JPA/hibernate/PostgresDB 和 Vaadin 8 : SQL select query to get data from inherited tables and show in Vaadin grid

javascript - 在谷歌地图API上用ID覆盖标记点

c - 如何在 Unix 环境中使用 C 以编程方式从 XSD 创建 XML

xml - 通过 mule esb 转发多部分请求

mysql - hibernate :MySql 与 ' ' 用户