org.hibernate.MappingException:关联引用未映射的类

时间:2011-07-08 11:40:00

标签: java hibernate-mapping

用户类的配置:

<class name="User" table="users" lazy="false">
    <id name="id" column="id">
        <generator class="native"/>
    </id>        
    <property name="type" column="type"/>         
    <many-to-one name="parent" column="parent"/>
    <property name="loginName" column="login_name" unique="true" not-null="true" index="idx_users_login_name" length="50"/>
    <property name="name" column="name" length="50"/>
    <property name="password" column="password"/>
    <property name="email" column="email" length="50"/>
    <property name="locale" column="locale" length="20"/>
    <property name="locked" column="locked"/>
    <many-to-one name="metadata" column="metadata_id"/>
    <set name="userSpaceRoles" cascade="all" inverse="true" lazy="false">
        <key column="user_id"/>
        <one-to-many class="UserSpaceRole"/>
    </set>      
</class>

,而MeetingItem类是:

<class name="MeetingItem" table="meeting_item">
    <id name="id" column="meeting_item_id" type="long">
        <generator class="native"/>
    </id>
    <property name="summary" column="summary" type="string"/>
    <property name="detail" column="detail" type="string"/>
    <many-to-one name="space" column="space_id"/>
    <property name="date" column="date" type="date"/>
    <list name="users" cascade="all" lazy="false">
        <key column="meeting_item_id"/>
        <index column="idx"/>
        <one-to-many class="User"/>
    </list>
</class>

问题是我得到了例外:

org.hibernate.MappingException: Association references unmapped class: info.domain.User
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2380)
at org.hibernate.cfg.HbmBinder.bindListSecondPass(HbmBinder.java:2231)
at org.hibernate.cfg.HbmBinder$ListSecondPass.secondPass(HbmBinder.java:2729)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:936)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:140)

列表的映射正在产生问题。我做错了什么?


编辑:

这两个配置位于不同的文件中,如果这两个配置放在同一个xml中,则问题不会发生。

2 个答案:

答案 0 :(得分:3)

请添加对映射文件的引用(将info.domain.User映射到hibernate.cfg.xml。

答案 1 :(得分:0)

请添加类级别注释以将类注册为Spring bean,即@Entity,因为您没有使用xml配置。