Domanda

Hi I'm trying to map this pojo Rent class to create his hibernate mapping file .

Rent.java (POJO):

  public class Rent implements Serializable {

     private static final long serialVersionUID = 1L;

       Employee employee;
       Client client;
       Car car;

    /* + getter and setter... */
  } 

My intention is to create web-application where the user can set which employee have rented a car to a client.So this is the implementation i've tried

Rent.hbm.xml :

<hibernate-mapping>
  <class name="com.google.musicstore.domain.Rent" table="RENT">
    <id name="id" column="RENT_ID">
       <generator class="native"/>
    </id>
    <one-to-one name="car"  class="com.project.domain.Car"
       cascade="save-update">
    </one-to-one>
    <one-to-one name="client"  class="com.project.domain.Client"
       cascade="save-update">
    </one-to-one>
    <many-to-one name="employee"  class="com.project.domain.Employee"
       cascade="save-update">
    </many-to-one>
  </class>
</hibernate-mapping>

But it gives me this error:

   [java] Initial SessionFactory creation failed.org.hibernate.MappingException: An association from the table RENT refers to an unmapped class: com.project.domain.Employee

What am i doing wrong? Thank you for the help.

I've also mapped all the entities in the hibernate.cfg.xml:

    <mapping resource="com/project/carRentalAgency/domain/Employee.hbm.xml"/>
    <mapping resource="com/project/carRentalAgency/domain/Client.hbm.xml"/>
    <mapping resource="com/project/carRentalAgency/domain/Car.hbm.xml"/>
    <mapping resource="com/project/carRentalAgency/domain/Rent.hbm.xml"/>

[EDIT] As request i've added the files Employee.hbm.xml

   <hibernate-mapping>
       <class name="com.project.carRentalAgency.domain.Employee" table="EMPLOYEE">
            <id name="id" type="long" access="field">
                <column name="ID" />
                <generator class="increment" />
            </id>
            <property name="name" type="java.lang.String" access="field">
                <column name="EMPLOYEE_NAME" />
           </property>
           <property name="surname" type="java.lang.String">
                <column name="EMPLOYEE_SURNAME" />
           </property>
           <property name="username" type="java.lang.String">
                <column name="EMPLOYEE_USERNAME" />
           </property>
           <property name="password" type="java.lang.String">
                <column name="EMPLOYEE_PASSWORD" />
           </property>

      </class>
   </hibernate-mapping>

È stato utile?

Soluzione 2

There are two possibilities I can think of:

(1) Your class name in Employee.hbm.xml is not a fully qualified class name

(2) You didn't declare all mapping resource in hibernate.cfg.xml.

You might need to provide more information such as Employee.hbm.xml and hibernate.cfg.xml in addition to Rent.hbm.xml for us to check.

Altri suggerimenti

I've found that usually this error occurred because the Build Action for the hibernate file classname.hbm.xml properties is not set to Embedded Resource.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top