title: JPA, Eclipselink, Many-to-many: dependent collection is not updating
body: <p>I have one many-to-many relationship in my model. There are two entities, Emergencies and Crews (crews can attend many emergencies, and vice versa). Code parts responsible for the relationship look as follows:</p>
  
  <pre><code>@JoinTable(name = "CREWS_ON_EMERGENCIES", joinColumns = {
      @JoinColumn(name = "EMERGENCY_ID", referencedColumnName = "EMERGENCY_ID", nullable = false)}, inverseJoinColumns = {
      @JoinColumn(name = "CREW_ID", referencedColumnName = "CREW_ID", nullable = false)})
  @ManyToMany(fetch= FetchType.EAGER)
  private Collection&lt;Crew&gt; crewList;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>@ManyToMany(mappedBy="crewList", fetch= FetchType.EAGER)
  private Collection&lt;Emergency&gt; emergencyList;
  </code></pre>
  
  <p>Crew is a dependent entity -- an <i>emergencyList</i> is updated when I add new Emergency with list of crews attended.</p>
  
  <p>Actually, the database is updated fine, and new records appear in the CREWS_ON_EMERGENCIES table right after the transaction is closed. But if add a new emergency and then display a list of all crews and emergencies they have attended, the last emergency will not be displayed (obviously, "emergencyList" is out of date). It will appear only when I restart a server (Tomcat) or in debug mode.</p>
  
  <p>Emergency save() code:</p>
  
  <pre><code> @Transactional
  public void save(Emergency e) {
      entityManager.persist(e);
      entityManager.flush();
  }
  </code></pre>
  
  <p>Selected crews are added automatically in the collection crewList by Spring MVC.</p>
  
  <p>Does anyone know why it happens in a way like this and what is the solution?</p>