title: NullPointerException trying to update an entity that contain a pivot table with version field
body: <p>I'm trying to update a pivot table through an entity where exist as a collection, my pivot table has a version field, when it updates throw an NullPointerException</p>
  
  <p>I'm using Java 8 and Hibernate as JPA provider</p>
  
  <p>Main entity
  "Carpeta.java"</p>
  
  <pre class="lang-java prettyprint-override"><code>@JoinColumn(name = "car_subcarpeta_id", referencedColumnName = "sub_id")
      @OneToOne(cascade = CascadeType.ALL)
      @Fetch(FetchMode.JOIN)
      private RjFicha fichaId;
  </code></pre>
  
  <p>Foreign key of "Carpeta.java"
  "SubCarpeta.java"</p>
  
  <pre class="lang-java prettyprint-override"><code> @OneToMany(mappedBy = "subCarpeta", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
      @Fetch(FetchMode.SUBSELECT)
      private Collection&lt;item&gt; itemCollection;
  </code></pre>
  
  <p>Pivot table relate to SubCarpeta
  "Item.java"</p>
  
  <pre class="lang-java prettyprint-override"><code>@JoinColumn(name = "i_subcarpeta_id", referencedColumnName = "sub_id")
      @ManyToOne
      private SubCarpeta subCarpeta;
  
  @Column(name = "i_version")
      @Version
      private Integer version;
  </code></pre>
  
  <p>This is the part of the trace when describe the source of the NullPointerException</p>
  
  <pre class="lang-sh prettyprint-override"><code>Caused by: java.lang.NullPointerException
      at org.hibernate.type.IntegerType.next(IntegerType.java:63)
      at org.hibernate.type.IntegerType.next(IntegerType.java:22)
      at org.hibernate.engine.internal.Versioning.increment(Versioning.java:92)
      at org.hibernate.event.internal.DefaultFlushEntityEventListener.getNextVersion(DefaultFlushEntityEventListener.java:383)
      at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:279)
      at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:143)
      at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:216)
      at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:85)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1300)
      at org.jboss.as.jpa.container.AbstractEntityManager.flush(AbstractEntityManager.java:459)
      ... 141 more
  
  </code></pre>