3

Possible Duplicate:
Hibernate - PropertyNotFoundException: Could not find a getter for

I am getting error when I am trying to run my code. Can you guys Please help. I have attached my mapping files. The issue here is that, am getting below error. " org.hibernate.PropertyNotFoundException: Could not find a getter for eployeedetail in class bean.Employee "

Here is my Employee Class

   package bean;

   import bean.EployeeDetails;

   public class Employee {


    int             EmpId;
    String          name;
    String          phone;
    EployeeDetails          Edetails;

   public EployeeDetails getEdetails() {
        return Edetails;
    }
    public void setEdetails(EployeeDetails eDetails) {
        Edetails = eDetails;
    }

And other getters ans setters.

EployeeDetails.hbm.xml

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

       <hibernate-mapping>
        <class name="bean.EployeeDetails" table="eployeedetail">
            <id name="EmpId">
                <column name="employee_id"/>
                <generator class="foreign" >
                <param name="property">eployee</param>
                </generator>
            </id>
            <one-to-one name="eployee" class="bean.Employee" constrained="true"></one-to-one>
            <property name="Address" column="ADDRESS"/>
        </class>
       </hibernate-mapping>

Employee.hbm.xml

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

       <hibernate-mapping>
        <class name="bean.Employee" table="eployee">
            <id name="EmpId" column="employee_id">
                <generator class="native" />
            </id>
            <one-to-one name="eployeedetail" class="bean.EployeeDetails"/>
            <property name="name" column="NAME"/>
            <property name="phone" column="PHONE"/>
        </class>
       </hibernate-mapping>
Community
  • 1
  • 1
Srivatsa N
  • 2,291
  • 4
  • 21
  • 36

2 Answers2

1

change your code from

 EployeeDetails   Edetails;

this

 EployeeDetails    Edetails = new EployeeDetails();
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40
  • Thanks Rajesh, But that dint help EployeeDetails edetails = new EployeeDetails(); public EployeeDetails getEdetails() { return edetails; } public void setEdetails(EployeeDetails edetails) { this.edetails = edetails; } Can you please help – Srivatsa N Nov 20 '12 at 11:31
  • check property name used in hbm for EployeeDetails should be same as your object name.of course case sensitive – rajesh kakawat Nov 20 '12 at 11:37
  • Yes Rajesh, It is same . I have attached my mapping file as a reply for @RAS – Srivatsa N Nov 20 '12 at 12:03
  • Is your object name is eployeedetail of EployeeDetails – rajesh kakawat Nov 21 '12 at 07:24
  • Yes Rajesh, Now I got my error. As mentioned by RAS it was in Employee.hbm.xml. Thanks a lot for your help – Srivatsa N Nov 22 '12 at 04:58
1

The problem is in Employee.hbm.xml. Whenever you specify a one-to-one tag, you need to specify 2 basic attributes:

  1. name which represents name of the property. In you case it should be Edetails & not eployeedetail. THIS IS THE REASON YOU'RE GETTING THE EXCEPTION.
  2. class which represents the class name which is associated as one-to-one with this class. In your case it should be EployeeDetails.

Change Employee.hbm.xml, change one-to-one tag attribute name to Edetails & your problem will be solved.

RAS
  • 8,100
  • 16
  • 64
  • 86
  • 1
    The description of the reason for the error is correct. But, the one-to-one doesn't have a column. one-to-one if not a many-to-one. It doesn't have a foreign key. It is based on linked primary keys or, bay using property-ref, linked foreign keys. – Stefan Steinegger Nov 21 '12 at 06:42
  • @StefanSteinegger, yes you're right. Thanks for pointing out. I've corrected the answer. – RAS Nov 21 '12 at 07:11
  • 1
    @Sri, If this answer is helpful to you you should accept it. – RAS Nov 22 '12 at 06:14