title: java EE Hibernate List many to many configure error
body: <p>I am making a java ee web application. I have User and Permission classes and User class have List that types of Permission. When hibernate gets user object form database, i want to get permissions of user from user_permission table ,too.  User and Permission has many-to-many relation. I am using Hibernate 5.4.1 . When SessionFactory configurating i get this error:</p>
  
  <pre><code>java.lang.NullPointerException
      org.hibernate.boot.model.source.internal.hbm.ModelBinder$AbstractPluralAttributeSecondPass.bindCollectionElement(ModelBinder.java:3557)
      org.hibernate.boot.model.source.internal.hbm.ModelBinder$AbstractPluralAttributeSecondPass.doSecondPass(ModelBinder.java:3136)
      org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1684)
      org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1652)
      org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:286)
      org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
      org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
      org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
  </code></pre>
  
  <p>my User class:</p>
  
  <pre><code>public class User
  {
      private int id;
      private String name;
      private String password;
      private List&lt;Permission&gt; permissions;
      public User(){}
      public User(String name,String password)
      {
          this.name=name;
          this.password=password;
      }
      public String getName()
      {
          return name;
      }
      public void setName(String name)
      {
          this.name=name;
      }
      public String getPassword()
      {
          return password;
      }
      public void setPassword(String password)
      {
          this.password=password;
      }
      public int getId()
      {
          return id;
      }
      public void setId(int id)
      {
          this.id=id;
      }
      public void clearPermissions()
      {
          permissions.clear();
      }
      public boolean hasPermission(Permission permission)
      {
          return permissions.contains(permission);
      }
      public void addPermission(Permission permission)
      {
          permissions.add(permission);
      }
      public void deletePermission(Permission permission)
      {
          permissions.remove(permission);
      }
      public List&lt;Permission&gt; getPermissions()
      {
          return permissions;
      }
      public void setPermissions(List&lt;Permission&gt; permissions)
      {
          this.permissions = permissions;
      }
  }
  </code></pre>
  
  <p>user class mapping : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="model.User" table="user"&gt;
          &lt;id name="id" type="int" column="id"&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;
          &lt;property name="name" column="name" type="string"/&gt;
          &lt;property name="password" column="password" type="string"/&gt;
          &lt;list name="permissions" table="user_permission" lazy="false"&gt;
              &lt;key column="user_id"/&gt;
              &lt;index column="id"/&gt;
              &lt;many-to-many class="Permission" column="permission_id"/&gt;
          &lt;/list&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>my Permission class: </p>
  
  <pre><code>public class Permission
  {
      private int id;
      private String name;
      public Permission() {}
      public Permission(int id, String name)
      {
          this.id=id;
          this.name=name;
      }
      public String getName()
      {
          return name;
      }
      public void setName(String name)
      {
          this.name=name;
      }
      public int getId()
      {
          return id;
      }
      public void setId(int id)
      {
          this.id=id;
      }
      public boolean equals(Object obj)
      {
          return ((Permission)obj).id==id;
      }
  }
  </code></pre>
  
  <p>Permission class mapping : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="model.Permission" table="permission"&gt;
          &lt;id name="id" type="int" column="id"&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;
          &lt;property name="name" column="name" type="string"/&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>