title: could not set a field value by reflection setter
body: <p>In a spring mvc application using hibernate and MySQL, I am getting an error which seems to indicate that a <code>Name</code> entity cannot find the setter for the <code>id</code> property of the <code>BaseEntity</code> superclass of the <code>Patient</code> entity. </p>
  
  <p><strong>How can I resolve this error?</strong>  </p>
  
  <p>Here is the error message:  </p>
  
  <pre><code>Caused by: org.hibernate.PropertyAccessException: could not set a field value by  
  reflection setter of myapp.mypackage.Name.patient
  </code></pre>
  
  <p>Here is the line of code that triggers the error:  </p>
  
  <pre><code>ArrayList&lt;Name&gt; names = (ArrayList&lt;Name&gt;) this.clinicService.findNamesByPatientID(patntId);
  </code></pre>
  
  <p>Here is the <code>BaseEntity</code>, which is the superclass of both <code>Patient</code> and <code>Name</code>:  </p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  @DiscriminatorFormula("(CASE WHEN dtype IS NULL THEN 'BaseEntity' ELSE dtype END)")
  public class BaseEntity {
  
      @Transient
      private String dtype = this.getClass().getSimpleName();
  
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE)
      protected Integer id;
  
      public void setId(Integer id) {this.id = id;}
      public Integer getId() {return id;}
  
      public void setDtype(String dt){dtype=dt;}
      public String getDtype(){return dtype;}
  
      public boolean isNew() {return (this.id == null);}
  
  }
  </code></pre>
  
  <p>Here is the <code>Patient</code> entity:  </p>
  
  <pre><code>@Entity
  @Table(name = "patient")
  public class Patient extends BaseEntity{
  
      @OneToMany(mappedBy = "patient")
      private Set&lt;Name&gt; names;
  
      protected void setNamesInternal(Set&lt;Name&gt; nms) {this.names = nms;}
  
      protected Set&lt;Name&gt; getNamesInternal() {
          if (this.names == null) {this.names = new HashSet&lt;Name&gt;();}
          return this.names;
      }
  
      public List&lt;Name&gt; getNames() {
          List&lt;Name&gt; sortedNames = new ArrayList&lt;Name&gt;(getNamesInternal());
          PropertyComparator.sort(sortedNames, new MutableSortDefinition("family", true, true));
          return Collections.unmodifiableList(sortedNames);
      }
  
      public void addName(Name nm) {
          getNamesInternal().add(nm);
          nm.setPatient(this);
      }
  
      //other stuff
  }
  </code></pre>
  
  <p>Here is the <code>Name</code> entity:  </p>
  
  <pre><code>@Entity
  @Table(name = "name")
  public class Name extends BaseEntity{
  
      @ManyToOne
      @JoinColumn(name = "patient_id")
      private Patient patient;
  
      public Patient getPatient(){return patient;}
      public void setPatient(Patient ptnt){patient=ptnt;}
  
  //other stuff
  
  }
  </code></pre>
  
  <p>The complete stack trace can be viewed <a href="https://jumpshare.com/v/FFU3GxotE52EgaBQukh8?b=4o6TEBFIJErhJTKY7yZB" rel="noreferrer">at this link</a>.</p>
  
  <p>The SQL generated by Hibernate for the above query is:  </p>
  
  <pre><code>select distinct hl7usname0_.id as id1_0_0_, givennames1_.id as id1_45_1_,  
  hl7usname0_.family as family1_44_0_, hl7usname0_.patient_id as patient3_44_0_,
  hl7usname0_.person_id as person4_44_0_, hl7usname0_.suffix as suffix2_44_0_,  
  hl7usname0_.usecode as usecode5_44_0_, hl7usname0_.codesystem as codesyst6_44_0_,  
  givennames1_.given as given2_45_1_, givennames1_.name_id as name3_45_1_,  
  givennames1_.name_id as name3_0_0__, givennames1_.id as id1_45_0__  
  from hl7_usname hl7usname0_  
  left outer join hl7_usname_given givennames1_ on hl7usname0_.id=givennames1_.name_id  
  where hl7usname0_.patient_id=1
  </code></pre>
  
  <p>When I run this query through the MySQL command line client, it returns the only record in the test database table.</p>