Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

" Could not find a getter for " Error [duplicate]

Tags:

hibernate

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>
like image 455
Srivatsa N Avatar asked Jan 24 '26 20:01

Srivatsa N


2 Answers

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.

like image 157
RAS Avatar answered Jan 27 '26 16:01

RAS


change your code from

 EployeeDetails   Edetails;

this

 EployeeDetails    Edetails = new EployeeDetails();
like image 29
rajesh kakawat Avatar answered Jan 27 '26 17:01

rajesh kakawat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!