我有以下课程:
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...
以及它的休眠配置文件:
<?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>
和制造商类:
public class Manufacturer implements Comparable<Manufacturer> {
private Long idManufacturer;
private String name;
我不断获取关联未映射的引用错误但我无法弄清楚为什么到目前为止。
编辑:制造商映射 -
<?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>
例外:
Initial SessionFactory creation failed.org.hibernate.MappingException:
Association references unmapped class: fr.synapture.model.company.Car
答案 0 :(得分:14)
初始SessionFactory创建失败..org.hibernate.MappingException: 关联引用未映射的类:fr.synapture.model.company.Car
这表明您已经映射了会话工厂不了解的类。您需要在会话工厂配置中包含Car。
要确认这一点,请在问题中包含Hibernate配置。
答案 1 :(得分:4)
在我的应用程序中,我将nHibernate映射项目与逻辑项目(2个项目)分开。我在“模型项目”中设置了所有映射,并且......出现此错误:关联引用未映射的类:
在我的sytuation中,我必须将MyClass.hbm.xml的属性设置为“Build Action - Enabled Resource”。
答案 2 :(得分:1)
Manufacturer
类也应该被映射,因此Company
应该被映射,因为它们都是从Car
映射引用的。
答案 3 :(得分:0)
只需在
中包含xmls Manufacturer.hbm.xml和Car.hbm.xml<mapping resource="Manufacturer.hbm.xml"/>
<mapping resource="Car.hbm.xml"/>
在你的hibernate.cfg.xml
中答案 4 :(得分:0)
要解决此问题,您应该将xml文件添加到hibernate配置中,请按照以下步骤操作:
通过此步骤,您将得到解决