无法创建sessionFactory object.org.hibernate.MappingException:关联引用未映射的类:

时间:2014-02-10 16:27:03

标签: hibernate hibernate-mapping

我有这个错误“无法创建sessionFactory object.org.hibernate.MappingException:关联引用未映射的类:事件”,我不知道为什么。谢谢你的帮助 这是我的类Event,Event.hbm.xml和hibernate.cfg.xml Event.java

public class Event {

    /** Attributs */

    private int id;     
    private String description;     
    private String hashtag;     
    private Date debut;     
    private Date fin;       
    private Position position;      
    private List<Marqueur> marqueurs;       
    private List<Invitation> invitations;       
    private User proprietaire;      
    private List<User> invites;

    /** 
     * Constructeur 
     * */ 
    public Event()
    {           
    }

    public Event(String description, String hashtag, Date debut, Date fin,
            Position position, User proprietaire) {
        super();
            ...
    }
        // Getters and setters    
}

Event.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping>
   <class name="Event" table="event">
      <meta attribute="class-description">
         This class contains the publicEvent detail. 
      </meta>
      <id name="id" type="int" column="id">
         <generator class="native"/>
      </id>
      <property name="description" column="description" type="string"/>
      <property name="hashtag" column="hashtag" type="string"/>
      <property name="debut" column="debut" type="date"/>
      <property name="fin" column="fin" type="date"/>
      <!--  Mapping ArrayList<Marqueur> marqueurs -->
      <list name="marqueurs" cascade="all">
         <key column="event_id"/>
         <list-index column="idx"/>
         <one-to-many class="Marqueur"/>
      </list>
      <!--  Mapping ArrayList<Invitation> invitations -->
      <list name="invitations" cascade="all">
         <key column="event_id"/>
         <list-index column="idx"/>
         <one-to-many class="Invitation"/>
      </list>
      <!--  Mapping User proprietaire -->
      <one-to-one name="proprietaire" class="User">
      </one-to-one>
      <!--  Mapping ArrayList<User> invites -->
      <list name="invites" cascade="all">
         <key column="event_id"/>
         <list-index column="idx"/>
         <one-to-many class="User"/>
      </list>
      <!--  Mapping Position position -->
      <one-to-one name="position" class="Position" constrained="true">
      </one-to-one>
      <!--  Mapping PublicEvent -->
      <joined-subclass name="PublicEvent" table="publicEvent">
      <key column="event_id"/>
      </joined-subclass>
      <!--  Mapping PrivateEvent -->
      <joined-subclass name="PrivateEvent" table="privateEvent">
      <key column="event_id"/>
      <property name="password" column="password" type="string"/>
      </joined-subclass>
   </class>
</hibernate-mapping>

的hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <!-- Database connection settings, Connect to HSQL, IN Memory  -->
        <property name="hibernate.connection.url">jdbc:mysql:***</property> 
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.username">***</property>
        <property name="hibernate.connection.password">***</property>

    <!-- List of XML mapping files -->
        <mapping resource="Demande.hbm.xml"/>
        <mapping resource="DernierePosition.hbm.xml"/>
        <mapping resource="Invitation.hbm.xml"/>
        <mapping resource="Marqueur.hbm.xml"/>
        <mapping resource="Position.hbm.xml"/>
        <mapping resource="User.hbm.xml"/>   
  </session-factory>
</hibernate-configuration>

其他错误: 无法创建sessionFactory object.org.hibernate.MappingException:关联引用未映射的类:Demande

Demande.java

public class Demande {

    /** Attributs */ 
    private int id;

    private PrivateEvent privateEvent;

    private User user;

}

Demande.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping>
   <class name="modele.Demande" table="demande">
      <meta attribute="class-description">
         This class contains the demande detail. 
      </meta>
      <id name="id" type="int" column="id">
         <generator class="native"/>
      </id>
      <!-- Mapping PrivateEvent privateEvent -->
      <one-to-one name="privateEvent" class="PrivateEvent" constrained="true">
      </one-to-one>
      <!-- Mapping User user -->
      <one-to-one name="user" class="User" constrained="true">
      </one-to-one>
   </class>
</hibernate-mapping>

PrivateEvent.java

public class PrivateEvent extends Event {
    String password;

    private ArrayList<Demande> demandes;
    ...
}

1 个答案:

答案 0 :(得分:1)

您尚未在会话工厂中提及事件,如下所示

<mapping resource="Event.hbm.xml"/>