2012-11-16 4 views
0

Je suis en train de mettre en œuvre un à une cartographie de l'association, mais il donne MappingException
fichier Student.hbm.xml:Mapping Exception en veille prolongée

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated 16 Nov, 2012 3:10:16 PM by Hibernate Tools 3.4.0.CR1 --> 
<hibernate-mapping> 
    <class name="com.sst.student.Student" table="STUDENT"> 
    <id name="studentId" type="java.lang.Long"> 
     <column name="STUDENT_ID" /> 
     <generator class="native" /> 
    </id> 
    <property name="studentName" type="string" length="20" column="STUDENT_NAME"/> 
    <many-to-one name="studentAddress" 
    column="STUDENT_ADDRESS" class="com.sst.student.Address" cascade="all" 
    unique="true"/> 
    </class> 

    </hibernate-mapping> 

mon fichier Address.hbm.xml:

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated 16 Nov, 2012 3:10:16 PM by Hibernate Tools 3.4.0.CR1 --> 
<hibernate-mapping> 
<class name="com.sst.student.Address" table="ADDRESS"> 
    <id name="addressId" type="java.lang.Long"> 
     <column name="ADDRESS_ID" /> 
     <generator class="native" /> 
    </id> 
    <property name="street" type="string" column="STREET" length="20"/> 
    <property name="city" type="string" column="CITY" length="20"/> 
    <property name="state" type="string" column="STATE" length="20"/> 
    <property name="country" type="string" column="COUNTRY" length="20"/> 
</class> 
</hibernate-mapping> 

au moment de la génération de code, je reçois l'exception suivante:

org.hibernate.MappingException: An association from the table STUDENT refers to an 
    unmapped class: com.sst.student.Address 

mon fichier CFG « de one2one.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> 
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="hibernate.connection.password">root$12</property> 
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306 
    /mysql</property> 
    <property name="hibernate.connection.username">root</property> 
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
    <property name="hibernate.show_sql">true</property> 
    <property name="hibernate.hbm2ddl.auto">create</property> 
    <mapping resource="com/sst/student/Student.hbm.xml"/> 
    <mapping resource="com/sst/student/Address.hbm.xml"/> 
</session-factory> 
</hibernate-configuration> 
+0

Avez-vous ajouté cette référence de fichier de mappage dans hibernate.cfg.xml? – RAS

+0

montrez-nous votre fichier de configuration hibernate. De plus, votre question dit «one-to-one» mais votre association dit «many-to-one». –

+0

J'ai ajouté mon fichier de configuration – venkyMCA

Répondre

0

Vous avez besoin d'un à plusieurs dans la cartographie Adresse hbm.xml.

Questions connexes