Reputation: 7403
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
Upvotes: 8
Views: 42761
Reputation: 1
There may be an simple file name error for the xml configs you can cross check those
Upvotes: 0
Reputation: 1785
To resolve it issue, you should add the xml files to hibernate configuration , please following the next steps:
With this steps your will be resolve
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 3121
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".
Upvotes: 4
Reputation: 7218
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.
Upvotes: 15
Reputation: 100706
Manufacturer
class should be mapped as well, and so should Company
since both are referenced from Car
mapping.
Upvotes: 1