title: Spring boot JPA persist manytomany unidirectionnal relationship
body: <p>I have a Spring Boot project (with JHipster) with 2 JPA Entities : User and Film.</p>
  <p>I've created an unidirectionnal ManyToMany relationship between them.
  User is the owner of the relationship.</p>
  <p>I would like to add films into favorite list of films of user (property 'favorites' in User entity).</p>
  <p>But when I try to add a film into favorites list, nothing is persisted into table 'user_film_favorite' (join table between the 2 entities).</p>
  <p>The mapping seems ok because when I manually enter data in this join table, I'm able to retrieve the list of films for a user.</p>
  <p>I've looked for a lot of similar issues here but can't find where the problem is.</p>
  <p>Entity User :</p>
  <pre><code>@Entity
  @Table(name = &quot;jhi_user&quot;)
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class User extends AbstractAuditingEntity implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      // Other properties
  
      @ManyToMany(cascade = CascadeType.PERSIST)
      @JoinTable(
          name = &quot;user_film_favorite&quot;,
          joinColumns = { @JoinColumn(name = &quot;user_id&quot;, referencedColumnName = &quot;id&quot;) },
          inverseJoinColumns = { @JoinColumn(name = &quot;movie_id&quot;, referencedColumnName = &quot;id&quot;) }
      )
      @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
      @BatchSize(size = 20)
      private List&lt;Film&gt; favorites = new ArrayList&lt;&gt;();
  </code></pre>
  <p>Entity Film :</p>
  <pre><code>@Entity
  @Table(name = &quot;film&quot;)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  public class Film implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = &quot;id&quot;)
      private Long id;
  
      @NotNull
      @Column(name = &quot;title&quot;, nullable = false)
      private String title;
  
      @Column(name = &quot;plot&quot;)
      private String plot;
  
      @Column(name = &quot;rating&quot;)
      private Float rating;
  </code></pre>
  <p>FilmService :</p>
  <pre><code>   /**
       * Add one film to current user favorites.
       *
       * @param id the id of the film.
       * @return the film saved into user favorites.
       */
      @Transactional(readOnly = true)
      public Optional&lt;FilmDTO&gt; addToFavorites(Long id) {
          log.debug(&quot;Request to get Film : {}&quot;, id);
          Optional&lt;Film&gt; filmOpt = filmRepository.findById(id);
          // Get current logged user with his favorites
          Optional&lt;User&gt; userOpt = userService.getUserWithFavorites();
          if (filmOpt.isPresent() &amp;&amp; userOpt.isPresent()) {
              User user = userOpt.get();
              user.getFavorites().add(filmOpt.get());
              userService.save(user); 
          }
          return filmOpt.map(filmMapper::toDto);
      }
  </code></pre>
  <p>UserService :</p>
  <pre><code>    /**
       * Save a user.
       *
       * @param user the entity to save.
       * @return the persisted entity.
       */
      public User save(User user) {
          log.debug(&quot;Request to save User : {}&quot;, user);
          return userRepository.save(user);
      }
  </code></pre>
  <p>If anyone could help me that would be really cool ! Thanks in advance :)</p>