views:

19

answers:

0

Hi,

I have three tables (DEVICES, DEVICE_DETAILS and LOCATIONS) which I want to map to two classes (Device and Location). To do this I use the following hibernate mappings:

Device.hbm.xml:

<hibernate-mapping>
<class name="bo.Device" table="DEVICES">
    <id name="deviceId" type="int">
        <column name="NR"/>
        <generator class="assigned"/>
    </id>
    <property name="enabled" type="java.lang.Boolean">
        <column name="ENABLED_STATUS"/>
    </property>

    <join inverse="true" optional="true" table="DEVICE_DETAILS">
        <key column="NR"/>

        <many-to-one name="location" class="bo.Location" column="LOC_NAME" insert="false" update="false"/>

        <property name="deviceTypeCode" type="string">
            <column length="10" name="TYPE_CODE"/>
        </property>
    </join>
</class>

Location.hbm.xml:

<hibernate-mapping>
  <class name="bo.Location" table="LOCATIONS">
    <id name="locationName" type="string">
      <column length="20" name="LOCATION_NAME" not-null="true"/>
      <generator class="assigned"/>
    </id>

    <property name="enabled" type="java.lang.Boolean">
      <column length="1" name="ENABLED_STATUS" not-null="true"/>
    </property>
  </class>
</hibernate-mapping>

Both the hbm files are in added to hibernate.cfg.xml. When I try to query a device ('From Device') I get the following exception:

org.hibernate.MappingException: An association from the table DEVICES refers to an unmapped class: bo.Location at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

I am able to query the locations ('From Location') so the mapping should work.

What am I doing wrong???