gpt4 book ai didi

Hibernate关联引用未映射的类异常

转载 作者:行者123 更新时间:2023-12-04 05:04:49 24 4
gpt4 key购买 nike

我有以下类(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...

它是 hibernate 配置文件:
<?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>

异常(exception):
Initial SessionFactory creation failed.org.hibernate.MappingException: 
Association references unmapped class: fr.synapture.model.company.Car

最佳答案

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



这表明您已经映射了 session 工厂不知道的类。您需要在 session 工厂配置中包括Car。

为了确认这一点,请在您的问题中包括Hibernate配置。

关于Hibernate关联引用未映射的类异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8288300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com