title: could not set a field value by reflection setter of <class>
body: <p><br/>
  I have seen a similar question in this forum, here it is <a href="https://stackoverflow.com/questions/18807321/mapping-value-in-junction-table-hibernate-propertyaccessexception-could-not-s">Mapping Value in Junction Table &amp; hibernate.PropertyAccessException: could not set a field value by reflection setter</a> <br/>
  I've applied the solution mentioned in this question but still I am facing the same problem. I don't know what am I missing.
  My classes - </p>
  
  <p><strong>EmployeeID.java</strong></p>
  
  <pre><code>@IdClass(value = EmployeeID.class)
  public class EmployeeID implements Serializable{
  
      private int empID;
      private int deptID;
  
      public EmployeeID() {
  
      }
  
      public EmployeeID(int empID, int deptID) {
          this.empID = empID;
          this.deptID = deptID;
      }
  
      public int getEmpID() {
          return empID;
      }
  
      public int getDeptID() {
          return deptID;
      }
  
      @Override
      public int hashCode() {
          final int prime = 31;
          int result = 1;
          result = prime * result + deptID;
          result = prime * result + empID;
          return result;
      }
      @Override
      public boolean equals(Object obj) {
          if (this == obj)
              return true;
          if (obj == null)
              return false;
          if (getClass() != obj.getClass())
              return false;
          EmployeeID other = (EmployeeID) obj;
          if (deptID != other.deptID)
              return false;
          if (empID != other.empID)
              return false;
          return true;
      }
  
  
  }
  </code></pre>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>@Entity(name="EMPLOYEE")
  @IdClass(value = EmployeeID.class)
  public class Employee {
  
      @Id @GeneratedValue
      @Column(name="EMP_ID")
      private int empID;
  
      @Id @GeneratedValue
      @Column(name="DEPT_ID")
      private int deptID;
  
      public int getEmpID() {
          return empID;
      }
      public void setEmpID(int empID) {
          this.empID = empID;
      }
      public int getDeptID() {
          return deptID;
      }
      public void setDeptID(int deptID) {
          this.deptID = deptID;
      }
  
      @Column(name="EMP_NAME")
      private String empName;
  
      public String getEmpName() {
          return empName;
      }
      public void setEmpName(String empName) {
          this.empName = empName;
      }
  }
  </code></pre>
  
  <p>And this is my test code -</p>
  
  <pre><code>try {
              Employee emp = new Employee();
              emp.setEmpName("New Employee");
  
              Session session = factory.openSession();
              session.beginTransaction();
  
              session.save(emp);
  
              session.getTransaction().commit();
              session.close();
          } catch (Exception e) {
              e.printStackTrace();
          } finally {
              factory.close();
          }
  </code></pre>
  
  <p>On running this test code I get this exception trace - </p>
  
  <pre><code>org.hibernate.PropertyAccessException: could not set a field value by reflection setter of EmployeeID.deptID
      at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:134)
      at org.hibernate.mapping.Component$ValueGenerationPlan.execute(Component.java:441)
      at org.hibernate.id.CompositeNestedGeneratedValueGenerator.generate(CompositeNestedGeneratedValueGenerator.java:121)
      at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
      at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
      at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
      at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
      at CompositeKeyDemo.main(CompositeKeyDemo.java:15)
  Caused by: java.lang.IllegalArgumentException: Can not set int field EmployeeID.deptID to org.hibernate.id.IdentifierGeneratorHelper$2
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
      at sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:98)
      at java.lang.reflect.Field.set(Field.java:741)
      at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:122)
      ... 12 more
  </code></pre>
  
  <p>Am i doing something silly.<br/><br/>
  Thanks in Advance !!</p>