title: Spring data jpa native query. Insert object
body: <p>I'm using a native query on my repository. I want to insert object data, but the query doesn't understand the object fields. How to solve this problem, I don't want to have a method with a lot of parameters.</p>
  
  <p>My class:</p>
  
  <pre><code>public class StudentDTO {
          private long numberzachetka;
          private String fio;
          private Date entrydate;
          private int course;
          private int numbergroup;
          private long specialty;
          private long faculty;
  //getters, setters..}
  </code></pre>
  
  <p>Native query:</p>
  
  <pre><code>@Query(value ="insert into student(numberzachetka,fiostudent,entrydate,course,numbergroup,specialtykey,facultynumber)" +
              " values" +
              " (:student.numberzachetka,:student.fio,:student.entrydate,:student.course,:student.numbergroup,:student.specialty,:student.faculty)", nativeQuery = true)
      void addNewStudent(@Param("student") StudentDTO studentDTO);
  </code></pre>
  
  <p>Student entity:</p>
  
  <pre><code>@Entity
  @Table(name="student")
  public class Student  {
  
      @Id
      @Column(name="numberzachetka", nullable = false)
      private long numberzachetka;
  
      @Column(name="fiostudent", nullable = false, length = 100)
      private String fio;
  
      @Temporal(TemporalType.DATE)
      @Column(name = "entrydate", nullable = false)
      private Date entrydate;
  
      @Column(name="course", nullable = false)
      private int course;
  
      @Column(name="numbergroup", nullable = false)
      private int numbergroup;
  
      @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      @JoinColumn(name = "specialtykey", nullable = false)
      private Specialty specialty;
  
      @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      @JoinColumn(name = "facultynumber", nullable = false)
      private Faculty faculty;
  
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "student")
      private Set&lt;Performance&gt; performances;
  </code></pre>