问题
Sorry to bother - perhaps this is a very simple question - but for some reason the version below fails to get parsed, whereas the version with set works fine. In fact, if I just take the set version and replace set with list I get:
nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
Thank you Misha
    <!-- bi-directional one-to-many association to SpreadsheetImportTemplateColumn -->
    <list name="columns">
<!--
    <set name="columns" lazy="false" inverse="true"
        cascade="all-delete-orphan" sort="natural"
        order-by="voided asc, preferred desc, date_created desc">
-->
        <key column="template_id" not-null="true" />
<!--
        <one-to-many class="SpreadsheetImportTemplateColumn" />
    </set>
-->
    </list>
    回答1:
You said
whereas the version with set works fine
Here goes list DOCTYPE
<!ELEMENT list (
    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*
)>
Ass you can see, list element needs either index or list-index element, a key element, and one of the following
- element
 - one-to-many
 - many-to-many
 - composite-element
 - many-to-any
 
Here goes list-index DOCTYPE
<!-- Declares the type and column mapping for a collection index (array or list index, or key of a map). -->
<!ELEMENT list-index (column?)>
<!ATTLIST list-index column CDATA #IMPLIED>
<!ATTLIST list-index base CDATA "0">
So you should use
<list name="columns">
    <key column="template_id" not-null="true"/>
    <list-index column="WHICH COLUMN SHOULD BE USED AS INDEX"/>
    <one-to-many class="SpreadsheetImportTemplateColumn" />
</list>
But if you want to use a list instead of a set and does not have a list-index column, you can use a bag instead. Initialize as follows
Collection<SpreadsheetImportTemplateColumn> columns = new ArrayList<SpreadsheetImportTemplateColumn>();
And define this mapping instead
<bag name="columns">
     <key column="template_id" not-null="true"/>
     <one-to-many class="SpreadsheetImportTemplateColumn"/>
</bag>
    回答2:
In Hibernate, a List must specify an index column.
See Section 6.2.3 of the Hibernate documentation.
来源:https://stackoverflow.com/questions/3580686/hibernate-one-to-many-mapping-works-with-a-list-but-not-a-set