title: Spring Data JPA: update a list of Entity using a list of input in a custom Query
body: <p>I have the following basic objects :</p>
  <pre><code>/* User class */
  
  import lombok.Data;
  import lombok.AllArgsConstructor;
  import javax.persistence.Entity;
  import javax.persistence.Id
  import javax.persistence.GeneratedValue;
  import javax.persistence.ManyToOne;
  
  @Data
  @Entity
  @AllArgsConstructor
  public class User {
  
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
  
    private String name;
    private String surname;
  
    @ManyToOne
    private Address address;
  }
  
  /* UserComposite class, used to load partial data from a user */
  
  import lombok.Data;
  import lombok.AllArgsConstructor;
  
  @Data
  @AllArgsConstructor
  public class UserComposite {
  
    private Long userId;
    private String name;
    private String surname;
  }
  </code></pre>
  <p>My goal here, is to update a list of User using a list of UserComposite as input. Here is what my DAO looks like :</p>
  <pre><code>/* UserDao class */    
  
  import org.springframework.data.jpa.repository.Modifying;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.transaction.annotation.Transactional;
  
  public interface UserDao extends JpaRepository&lt;User, Long&gt; {
  
    @Transactional
    @Modifying
    @Query(&quot;update User u set u.name = uc.name , &quot;
        + &quot;u.surname = uc.surname &quot;
        + &quot;where u.id = uc.userId &quot;
        + &quot;and UserComposite uc in (?1)&quot;)
    void updateUserFromCompositeList(List&lt;UserComposite&gt; userCompositeList);
  }
  </code></pre>
  <p>However, this does not work. I have a hard time matching the data from the input with the data saved in my database, especially as UserComposite is not an entity.</p>
  <p>Is there a way around this problem ?</p>