title: JPA system exception error accesing field
body: <p>I'm trying to implement a unidirectional many to many relationship between entities with spring+JPA. </p>
  
  <p>After a few tries changing hibernate versions I don't know whats the cause</p>
  
  <blockquote>
    <p>Caused by: org.springframework.orm.jpa.JpaSystemException: Error accessing field [private java.lang.Integer com.uca.refactor2.model.Achievement.id] by reflection for persistent property [com.uca.refactor2.model.Achievement#id] : 1; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Integer com.uca.refactor2.model.Achievement.id] by reflection for persistent property [com.uca.refactor2.model.Achievement#id] : 1</p>
  </blockquote>
  
  <p>User.java</p>
  
  <pre><code>@Entity
  @Table(name="USER")
  public class User implements Serializable {
  
  private static final long serialVersionUID = 4402583037980335445L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer id;
  private String firstName;
  private String lastName;
  @Column(unique = true)
  private String username;
  private String password;
  @Enumerated(EnumType.STRING) 
  private UserType  userType;
  
  @OneToMany(cascade=CascadeType.ALL, mappedBy="joinedUserAchievementId.user")
  private List&lt;JoinedUserAchievement&gt; joinedUserAchievementList = new ArrayList&lt;JoinedUserAchievement&gt;();
  
  public User() {}
  
  public User(Integer id) {
      this.id = id;
  }
  public User(String username, String firstName, String lastName,
          String password, UserType userType) {
      this.username = username;
      this.firstName = firstName;
      this.lastName = lastName;
      this.password = password;
      this.userType = userType;
  }
  
  
  public List&lt;JoinedUserAchievement&gt; getAllAchievement() {
          return joinedUserAchievementList;
  }
  public void addAchievement(Achievement achievement) {
      // Notice a JoinedUserAchievement object
      Date dateOfAcquisition = new Date();
      JoinedUserAchievement joinedUserAchievement = new JoinedUserAchievement(new JoinedUserAchievement.JoinedUserAchievementId(this, achievement),dateOfAcquisition );
      joinedUserAchievement.setAchievementId(achievement.getId());
      joinedUserAchievementList.add(joinedUserAchievement);
  }
  //set and gets
  </code></pre>
  
  <p>JoinedUserAchievement.java</p>
  
  <pre><code>@Entity
  @Table(name="USER_ACHIEVEMENT")
  public class JoinedUserAchievement {
  
  public JoinedUserAchievement() {}
  
  public JoinedUserAchievement(JoinedUserAchievementId joinedUserAchievementId, Date dateOfAcquisition) {
      this.joinedUserAchievementId = joinedUserAchievementId;
      this.dateOfAcquisition = dateOfAcquisition;
  }
  
  @ManyToOne(targetEntity = Achievement.class)
  @JoinColumn(name="id", insertable=false, updatable=false)
  private Integer achievementId;
  
  private Date dateOfAcquisition;
  
  public String getDate()  {
      DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
      Date date = dateOfAcquisition;
      return dateFormat.format(date); 
  }
  
  public Integer getAchievementId() {
      return achievementId;
  }
  
  public void setAchievementId(Integer achievementId) {
      this.achievementId = achievementId;
  }
  
  @EmbeddedId
  private JoinedUserAchievementId joinedUserAchievementId;
  
  
  // required because JoinedUserAchievments contains composite id
  @Embeddable
  public static class JoinedUserAchievementId implements Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = -9180674903145773104L;
  
  
      @ManyToOne
      @JoinColumn(name="USER_ID")
      private User user;
  
      @ManyToOne
      @JoinColumn(name="ACHIEVEMENT_ID")
      private Achievement achievement;
  
      // required no arg constructor
      public JoinedUserAchievementId() {}
  
      public JoinedUserAchievementId(User user, Achievement achievement) {
          this.user = user;
          this.achievement = achievement;
      }
  
      public JoinedUserAchievementId(Integer userId, Integer achievementId) {
          this(new User(userId), new Achievement(achievementId));
      }
  
      public User getUser() {
          return user;
      }
  
      public Achievement getAchievement() {
          return achievement;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      public void setAchievement(Achievement achievement) {
          this.achievement = achievement;
      }
      @Override
      public boolean equals(Object instance) {
          if (instance == null)
              return false;
  
          if (!(instance instanceof JoinedUserAchievementId))
              return false;
  
          final JoinedUserAchievementId other = (JoinedUserAchievementId) instance;
          if (!(user.getId().equals(other.getUser().getId())))
              return false;
  
          if (!(achievement.getId().equals(other.getAchievement().getId())))
              return false;
  
          return true;
      }
  
      @Override
      public int hashCode() {
          int hash = 7;
          hash = 47 * hash + (this.user != null ? this.user.hashCode() : 0);
          hash = 47 * hash + (this.achievement != null ? this.achievement.hashCode() : 0);
          return hash;
      }
  }
  }
  </code></pre>
  
  <p>Achievement.java</p>
  
  <pre><code>@Entity
  @Table(name="ACHIEVEMENT")
  public class Achievement implements Serializable{
  
  private static final long serialVersionUID = 7747630789725422177L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  
  private Integer id;
  private String name;
  private Integer points;
  
  
  public Achievement() {
  
  }
  public Achievement(String name, Integer points) {
      this.name = name;
      this.points = points;
  }
  
  public Achievement(Integer id) {
      this.id = id;
  }
  //set and gets
  </code></pre>
  
  <p>I've also tried to make this relationship bidirectional and it didn't work, so I may be missing something</p>
  
  <p>Also before this I had achievement objects instead of achievementId on joinedUserAchievement, it worked but I think its not what I need, I don't need to get every achievement object always, with only the id is fine.</p>