title: JPA can not set Long field to Long
body: <p>I guess that I have a mistake somewhere...<br>
  It's supposed that 1 player has 1 stats table (oneToOne)</p>
  
  <p>Class Player:</p>
  
  <pre><code>@Component
  @Entity
  @Table(name = "player")
  public class Player {
  
      @Id
      @GeneratedValue
      @JsonView(View.Summary.class)
      @Column(name = "id")
      private Long id;
  
      @Column(name = "uid", unique = true, nullable = false)
      @JsonView(View.Summary.class)
      private Long uid;
  
      @OneToOne(mappedBy = "player", cascade = CascadeType.ALL)
      @JsonView(View.Summary.class)
      private Stats stats;
      ....
  </code></pre>
  
  <p>Class Stats:</p>
  
  <pre><code>@Component
  @Entity
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  @Table(name = "stats")
  public class Stats implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE)
      @JsonView(View.Summary.class)
      @Column(name = "id")
      private Long id;
  
      @OneToOne
      @JoinColumn(name = "player_uid", referencedColumnName = "uid", nullable = false)
      @JsonView(View.Summary.class)
      private Player player;
      ....
  </code></pre>
  
  <p>Class PlayerDAO:</p>
  
  <pre><code>public interface JPAPlayerDAO extends JpaRepository&lt;Player, Long&gt; {
      Player findByUid(Long uid);
      Player findByName(String name);
  }
  </code></pre>
  
  <p>If I do this, it's fine:</p>
  
  <pre><code>Player p = new Player();
  p.setUid(123L);
  p.setName("Mike");
  updater.saveOrUpdatePlayer(p);
  p = playerDAO.findOne()
  </code></pre>
  
  <p>If I try to find it by name or uid, I get an error:</p>
  
  <pre><code>Player p = new Player();
  p.setUid(123L);
  p.setName("Mike");
  updater.saveOrUpdatePlayer(p);
  p = playerDAO.findByName("Mike")
  or
  p = playerDAO.findByUid(123L)
  ....
  Caused by: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field...
  Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field ...entities.Player.uid to java.lang.Long
  </code></pre>
  
  <p>I think that it could be something wrong with my oneToOne reference.</p>