title: Java hibernate PropertyAccessException
body: <p>I try to use Hibernate 4.1.5.
  When i try to add new row in Community, i've got an error:</p>
  
  <pre><code>Exception in thread "main" Hibernate: insert into users_communities (community_id, user_id) values (?, ?)
  dbService.DBException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of dbService.dataSets.UsersDataSet.id
      at dbService.DBService.addUser(DBService.java:290)
      at accounts.AccountService.addUser(AccountService.java:131)
      at main.Main.main(Main.java:83)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of dbService.dataSets.UsersDataSet.id
      at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:60)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:346)
      at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4746)
      at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4465)
      at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:243)
      at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:293)
      at org.hibernate.type.EntityType.getIdentifier(EntityType.java:537)
      at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:165)
      at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:899)
      at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1308)
      at org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:67)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
      at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
      at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
      at dbService.DBService.addUser(DBService.java:286)
      ... 7 more
  Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field dbService.dataSets.UsersDataSet.id to java.lang.Long
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
      at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
      at java.lang.reflect.Field.get(Field.java:393)
      at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:57)
      ... 26 more
  </code></pre>
  
  <p>These are my Entity-classes:</p>
  
  <p><strong><code>Entity : "community"</code></strong></p>
  
  <pre><code>@Entity
  @Table(name = "community")
  public class CommunityDataSet implements Serializable { // Serializable Important to Hibernate!
      private static final Long serialVersionUID = -8706689714326132798L;
  
      @Column(name = "user_id")
      private Long id;
  
      @Id
      @Column(name = "community_id", unique = true, updatable = false)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long community_id;
  
      @Column(name = "community_name")
      private String community_name;
  
      @ManyToMany(targetEntity = UsersDataSet.class, fetch = FetchType.LAZY)
      @JoinTable(name = "users_communities", joinColumns = @JoinColumn(name = "community_id"),
          inverseJoinColumns = @JoinColumn(name = "user_id"))
     private Set&lt;Long&gt; users = new HashSet&lt;&gt;();
  
     //Important to Hibernate!
     @SuppressWarnings("UnusedDeclaration")
     public CommunityDataSet() {
     }
  
     public CommunityDataSet(String community_name) {
         //this.setId(id);
         //this.setCommunityId(community_id);
         this.setCommunityName(community_name);
     }
  
     public CommunityDataSet(Long user_id, String community_name) {
         this.setUser(user_id);
         //this.setCommunityId(community_id);
         this.setCommunityName(community_name);
     }
  
     @SuppressWarnings("UnusedDeclaration")
  
  
     public Long getId() { return id; }
  
     private void setId(Long id) { this.id = id; }
  
     public Long getCommunityId() { return community_id; }
  
     private void setCommunityId(Long community_id) {
         this.community_id = community_id;
     }
  
     public String getCommunityName() { return community_name;}
  
     public void setCommunityName(String name) { this.community_name = name;}
  
     public Set&lt;Long&gt; getUsers() { return users; }
  
     //public void setUsers(Set&lt;Long&gt; users) { this.users = users; }
  
     public void setUser(Long user) {
         this.users.add(user);
     }
  
     public String toString() {
         return "CommunityDataSet{" +
              //   "id=" + id +
                 ", community_id='" + community_id + '\'' +
              '}';
     }
  }
  </code></pre>
  
  <p><strong><code>Entity = "users"</code></strong></p>
  
  <pre><code>@Entity
  @Table(name = "users")
  public class UsersDataSet implements Serializable { // Serializable Important to Hibernate!
      private static final Long serialVersionUID = -8706689714326132798L;
  
      @Id
      @Column(name = "user_id")
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id = 0L;
  
      @Column(name = "login", unique = true, updatable = false)
      private String login;
  
      @Column(name = "password", updatable = false)
      private String password;
  
      @Column (name = "name")
      private String name;
  
      @Column (name = "surname")
      private String surname;
  
      @ManyToMany(targetEntity = CommunityDataSet.class, mappedBy="users", fetch = FetchType.LAZY)
  private Set&lt;Long&gt; communities = new HashSet&lt;&gt;();
  
      //Important to Hibernate!
      @SuppressWarnings("UnusedDeclaration")
      public UsersDataSet() { }
  
      public UsersDataSet(Long id, String login, String password, String name, String surname) {
         this.setId(id);
         this.setLogin(login);
         this.setPassword(password);
         this.setName(name);
         this.setSurname(surname);
      }
  
      @SuppressWarnings("UnusedDeclaration")
      public UsersDataSet(Long id, String login, String password) {
          this.setId(id);
          this.setLogin(login);
          this.setPassword(password);
          this.setName(login);
          this.setSurname("");
      }
  
      public UsersDataSet(String login, String password) {
          this.setId(++this.id);
          this.setLogin(login);
          this.setPassword(password);
          this.setName(login);
          this.setSurname("");
      }
  
      @SuppressWarnings("UnusedDeclaration")
  
      public Long getId() { return id; }
  
      private void setId(Long id) { this.id = id; }
  
      public String getLogin() { return login; }
  
      public void setLogin(String login) { this.login = login; }
  
      public String getPassword() { return password; }
  
      public void setPassword(String password) { this.password = password; }
  
      public String getName() { return name; }
  
      public void setName(String name) { this.name = name; }
  
      public String getSurname() { return surname; }
  
      public void setSurname(String surname) { this.surname = surname; }
  
      public Set&lt;Long&gt; getCommunities() { return communities;  }
  
      public void setCommunities(Set&lt;Long&gt; communities) { this.communities = communities; }
  
      public void setCommunity(Long community_id) { this.communities.add(community_id); }
  
      @Override
      public String toString() {
          return "UserDataSet{" +
              "id=" + id +
              ", login='" + login + '\'' +
              '}';
      }
  }
  </code></pre>