0

我对 Hibernate 集合映射有点迷失。尝试在 Eclipse Hibernate 透视图中添加持久性配置会引发以下问题:

Invalid ORM mapping file.
Error parsing XML (line14 : column 16): 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*)".
Error parsing XML (line17 : column 15): The content of element type "map" must match "(meta*,subselect?,cache?,synchronize*,comment?,key,(map-key|composite-map-key|map-key-many-to-many|index|composite-index|index-many-to-many|index-many-to-any),(element|one-to-many|many-to-many|composite-element|many-to-any),loader?,sql-insert?,sql-update?,sql-delete?,sql-delete-all?,filter*)".

实际映射配置如下:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="core.Server" table="server" schema="imdb">
        <id name="serverId" type="java.lang.Integer">
            <column name="SERVER_ID" />
            <generator class="identity" />
        </id>   
        <list name="sessions" inverse="true">
            <key column="serverID" not-null="true"/>
            <list-index column="SERVER_SESSION_NUMBER" />           
            <one-to-many class="core.Session"/>
        </list> 
        <map name="users" inverse="true">
            <key column="serverID" not-null="true"/>
            <map-key type="string" column="SERVER_USER_NUMBER"/>
            <one-to-many class="core.User"/>
        </map>  
    </class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="core.User" table="user" schema="imdb">
        <id name="userId" type="java.lang.Integer">
            <column name="USER_ID" />
            <generator class="identity" />
        </id>   
        <property name="login" column="LOGIN" type="string" />          
        <property name="online" column="ONLINE" type="boolean" />   
        <property name="last_message" column="LAST_MESSAGE" type="string" />  
        <property name="newmessage" column="NEW_MESSAGE" type="boolean" />  
        <many-to-one name="serverID" column="SERVER_ID" class="core.Server"/>
        <list name="sessions" inverse="true">
            <key column="USER_ID" not-null="true"/>
            <one-to-many class="core.Session"/>
            <list-index column="USER_SESSION_NUMBER" />
        </list>     
    </class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="core.Session" table="session" schema="imdb">
        <id name="sessionID" type="java.lang.Integer">
            <column name="SESSION_ID" />
            <generator class="identity" />
        </id>   
        <many-to-one name="serverID" column="SERVER_ID" class="core.Server"/>
        <many-to-one name="userID" column="USER_ID" class="core.User/>
    </class>
</hibernate-mapping>

感谢您的帮助!

4

1 回答 1

2

订单是特定的(并在错误消息中提供给您)。这不是一个休眠的东西,它是一个 XML 模式的东西。

所以让标签的顺序正确,例如: <list-index> 需要在 <one-to-many > 之前

编辑:并非所有表格都是错误的。第一个没问题。第二个有两个错误,应该是

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="core.User" table="user" schema="imdb">
        <id name="userId" type="java.lang.Integer">
            <column name="USER_ID" />
            <generator class="identity" />
        </id>   
        <property name="login" column="LOGIN" type="string" />          
        <property name="online" column="ONLINE" type="boolean" />   
        <property name="last_message" column="LAST_MESSAGE" type="string" />  
        <property name="newmessage" column="NEW_MESSAGE" type="boolean" />  
        <list name="sessions" inverse="true">
            <key column="USER_ID" not-null="true"/>
            <list-index column="USER_SESSION_NUMBER" />
            <one-to-many class="core.Session"/>          
        </list>   
        <many-to-one name="serverID" column="SERVER_ID" class="core.Server"/>
    </class>
</hibernate-mapping>

你的第三个是错误的,因为它在 class="core.User 之后缺少引号 - 应该是

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="core.Session" table="session" schema="imdb">
        <id name="sessionID" type="java.lang.Integer">
            <column name="SESSION_ID" />
            <generator class="identity" />
        </id>   
        <many-to-one name="serverID" column="SERVER_ID" class="core.Server"/>
        <many-to-one name="userID" column="USER_ID" class="core.User"/>
     </class>
</hibernate-mapping>
于 2012-05-18T12:48:08.827 回答