8

I have the following class:

public class Car implements Comparable<Car>{

private long idCar;

private String model;

private String immat; //Car License Plate

private Company company;

private Manufacturer manufacturer;    

private Calendar registrationDate;

private Calendar lastControlDate;

//Has empty constructor + Getters and setters here onwards...

and it's hibernate configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="Car" table="cars" lazy="true"> 
    <id name="idCar" type="long" column="idCar">
      <generator class="native" />
    </id>

    <property name="model" type="string" column="model" />
    <property name="immat" type="string" column="immat" />
    <property name="registrationDate" type="date" column="registrationDate" />
    <property name="lastControlDate" type="date" column="lastControlDate" />

    <many-to-one name="company" class="fr.model.company.Company" column="idCompany"
     not-null="true" />
    <many-to-one name="manufacturer" class="fr.model.component.Manufacturer"
             column="idManufacturer" not-null="true" />    

  </class>
</hibernate-mapping>

and the Manufacturer class:

public class Manufacturer implements Comparable<Manufacturer> {

private Long idManufacturer;
private String name;

I keep getting the association unmapped references error but I can't figure out why so far.

Edit: Manufacturer mapping -

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="Manufacturer" table="manufacturer">
      <id name="idManufacturer" type="long" column="idManufacturer">
            <generator class="native" />
    </id>

    <property name="name" type="string" not-null="true" />

  </class>

</hibernate-mapping>

Exception:

Initial SessionFactory creation failed.org.hibernate.MappingException: 
Association references unmapped class: fr.synapture.model.company.Car
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Dark Star1
  • 6,986
  • 16
  • 73
  • 121
  • Looks like it could've been an IDE problem. I rewound the modifications and restarted the dev path but started with those modifications first and the error hasn't cropped up. – Dark Star1 Nov 28 '11 at 14:04

6 Answers6

15

Initial SessionFactory creation failed.org.hibernate.MappingException: Association references unmapped class: fr.synapture.model.company.Car

This suggests that you've mapped a class which the session factory doesn't know about. You need to include Car in the Session Factory configuration.

To confirm this please could you include the Hibernate configuration in your questions.

Alex Barnes
  • 7,174
  • 1
  • 30
  • 50
  • I should mention that the project is inherited and I'm just modifying it to add some things to it so the Cars, Manufacturer, classes are all I've added. – Dark Star1 Nov 27 '11 at 21:36
  • Yep. So you also need to tell the session factory about them. As well as mapping them. Can you post the session factory configuration? That is hibernate.cfg.xml if you're using XML. – Alex Barnes Nov 27 '11 at 21:42
  • Every class is specified in the mapping resource with company being specified as joined subclass of another: http://fpaste.org/6rZD/ – Dark Star1 Nov 27 '11 at 21:42
  • It's posted in the link above. Company is defined under Society.hbm.xml mapping – Dark Star1 Nov 27 '11 at 21:50
  • It does look like the Car entity should be known to the session factory. I've only ever seen that exception when an entity isn't marked as @Entity (not relevant to you) and when an Entity hasn't been registered in the session factory. I'm not all that familiar with xml configuration but it looks ok. – Alex Barnes Nov 27 '11 at 22:00
  • The config was created by the guy who started development on the project and the only changes I've made to the copy is to add the hbms to the new POJOs and change the datasource infos. Other than that they should still work. – Dark Star1 Nov 27 '11 at 22:03
4

In my app I have nHibernate mapping project separate with logic project (2 projects). I have set all mappings in "model project" and... have this error: Association references unmapped class:

In my sytuation, I had to set properties of MyClass.hbm.xml to "Build Action - Enabled Resource".

zchpit
  • 3,071
  • 4
  • 28
  • 43
1

Manufacturer class should be mapped as well, and so should Company since both are referenced from Car mapping.

ChssPly76
  • 99,456
  • 24
  • 206
  • 195
  • It is mapped. I'll post it up in edit. Just as an aside should the Manufacturer pojo contain a set of the "Car" type? – Dark Star1 Nov 27 '11 at 19:58
  • @DarkStar1 Is `Car` mapped as well? What's the exact error message you're getting? – ChssPly76 Nov 27 '11 at 20:26
  • The error I get is: Initial SessionFactory creation failed.org.hibernate.MappingException: Association references unmapped class: fr.synapture.model.company.Car Yes Car is mapped as is shown the the above mapping. – Dark Star1 Nov 27 '11 at 20:33
0

Just include both the xmls Manufacturer.hbm.xml and Car.hbm.xml in the

<mapping resource="Manufacturer.hbm.xml"/>
<mapping resource="Car.hbm.xml"/>

in your hibernate.cfg.xml

0

To resolve it issue, you should add the xml files to hibernate configuration , please following the next steps:

  1. Open hibernate perspective
  2. Select your configuration, for example "hibernate configuration"
  3. Right click in your configuration
  4. Select edit configuration
  5. Open Mappings tab
  6. Click on Add button
  7. Find and select "Manufacturer.hbm.xml" and "Car.hbm.xml"
  8. Click on Ok button
  9. Click on Ok button

With this steps your will be resolve

Jorge Santos Neill
  • 1,635
  • 13
  • 6
0

There may be an simple file name error for the xml configs you can cross check those

Raj
  • 1