title: Hibernate: Error accessing field [private java.lang.Integer ] by reflection for persistent property
body: <p>I have strange issue when I try to get entities property:</p>
  
  <pre><code>Hibernate: 
      select
          tarifklsk0_.ID as ID1_12_0_,
          tarifklsk0_.FK_TARIF as FK_TARIF2_12_0_,
          tarifservp1_.FK_TARIF as FK_TARIF2_11_1_,
          tarifservp1_.ID as ID1_11_1_,
          tarifservp1_.ID as ID1_11_2_,
          tarifservp1_.FK_TARIF as FK_TARIF2_11_2_,
          tarifservp1_.N1 as N3_11_2_ 
      from
          TR.TARIFXKLSK tarifklsk0_ 
      left outer join
          TR.TARIF_SERV_PROP tarifservp1_ 
              on tarifklsk0_.FK_TARIF=tarifservp1_.FK_TARIF 
      where
          tarifklsk0_.ID=?
  Jun 13, 2016 7:38:26 AM org.hibernate.event.internal.DefaultLoadEventListener doOnLoad
  INFO: HHH000327: Error performing load command : org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Integer TarifKlsk.fkTarif] by reflection for persistent property [TarifKlsk#fkTarif] : 1027303
  Exception in thread "main" org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Integer TarifKlsk.fkTarif] by reflection for persistent property [TarifKlsk#fkTarif] : 1027303
      at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:43)
      ....skipped...
  Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Integer field TarifKlsk.fkTarif to java.lang.Integer
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)       
  </code></pre>
  
  <p>My entities:</p>
  
  <p><em>TarifKlsk</em></p>
  
  <pre><code>import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  
  import org.hibernate.annotations.BatchSize;
  
  @SuppressWarnings("serial")
  @Entity
  @Table(name = "TARIFXKLSK", schema="TR")
  public class TarifKlsk implements java.io.Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "ID", updatable = false, nullable = false)
      private Integer id;
  
      @OneToMany(fetch = FetchType.EAGER)
      @JoinColumn(name="FK_TARIF", referencedColumnName="FK_TARIF")
      @BatchSize(size = 50)
      private Set&lt;TarifServProp&gt; tarifservprop = new HashSet&lt;TarifServProp&gt;(0);
  
      @Column(name = "FK_TARIF", updatable = false, nullable = false)
      private Integer fkTarif;
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public Set&lt;TarifServProp&gt; getTarifservprop() {
          return tarifservprop;
      }
  
      public void setTarifservprop(Set&lt;TarifServProp&gt; tarifservprop) {
          this.tarifservprop = tarifservprop;
      }
  
      public Integer getFkTarif() {
          return fkTarif;
      }
  
      public void setFkTarif(Integer fkTarif) {
          this.fkTarif = fkTarif;
      }
  
  }
  </code></pre>
  
  <p><em>TarifServProp</em></p>
  
  <pre><code>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @SuppressWarnings("serial")
  @Entity
  @Table(name = "TARIF_SERV_PROP", schema="TR")
  public class TarifServProp implements java.io.Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "ID", updatable = false, nullable = false)
      private Integer id;
  
      @Column(name = "FK_TARIF", updatable = false, nullable = false)
      private Integer fkTarif;
  
      public Integer getId() {
          return id;
      }
  
      @Column(name = "N1", updatable = false, nullable = false)
      private Integer n1;
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public Integer getFkTarif() {
          return fkTarif;
      }
  
      public void setFkTarif(Integer fkTarif) {
          this.fkTarif = fkTarif;
      }
  
      public Integer getN1() {
          return n1;
      }
  
      public void setN1(Integer n1) {
          this.n1 = n1;
      }
  
  }
  </code></pre>
  
  <p>My test module:</p>
  
  <pre><code>    public static void main(String[] args) {
          SessionFactory sf = HibernateUtil.getSessionFactory();
          Session sess = sf.openSession();
          sess.beginTransaction();
  
          TarifKlsk k2=sess.get(TarifKlsk.class, 1027303);
          for (TarifServProp t : k2.getTarifservprop()) {
               System.out.println("Tar="+t.getN1());
          }
  
          System.out.println("End init");
  </code></pre>
  
  <p>What am I doing wrong? I've checked  all fields of these entities and all of them named properly....</p>
  
  <p><strong>Updt</strong>
  <em>My POM.xml</em></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.journaldev.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;HibernateEHCacheExample&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;description&gt;Hibernate Secondary Level Cache Example using EHCache implementation&lt;/description&gt;
  
      &lt;dependencies&gt;
          &lt;!-- Hibernate Core API --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.1.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- EHCache Core APIs --&gt;
          &lt;!-- http://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
              &lt;artifactId&gt;ehcache-core&lt;/artifactId&gt;
              &lt;version&gt;2.6.11&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
              &lt;version&gt;5.2.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- EHCache uses slf4j for logging --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-simple&lt;/artifactId&gt;
              &lt;version&gt;1.7.5&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>Upd2</strong></p>
  
  <p>I've found out that my child entity doesn't contain records with fk_tarif corresponding to the fk_tarif from master... but I think it doesn't matter, why is error exists?  </p>