2

The configuration for User class :

<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>

and for the class MeetingItem is:

<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>

The problem is I am getting the exception:

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)

The mapping of the list is creating the problem. What I am doing wrong?


Edit:

This two configuration resides in different file, if these two are placed in same xml then the problem is not occurring.

2 Answers 2

5

please add a reference to the mapping file (which maps info.domain.User) into hibernate.cfg.xml.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks. But I don't have hibernate.cfg.xml, as everything is controlled by Spring. Also the table corresponding to info.domain.User is created before the attempt for creating info.domain.MeetingItem.
you must be linking the mapping files (.hbm.xml) to spring.. you need to add the mapping file for info.domain.User class there.
0

Please add class level annotations to register the class as a Spring bean, i.e @Entity in this case since you are not using xml configuration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.